fix:#47 added ssr check

This commit is contained in:
Elmar Kresse
2024-07-06 18:35:37 +02:00
parent df03c6cd48
commit 390f6b2b57

View File

@@ -19,14 +19,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<script lang="ts" setup> <script lang="ts" setup>
import tokenStore from "@/store/tokenStore.ts"; import tokenStore from "@/store/tokenStore.ts";
import { useToast } from "primevue/usetoast"; import { useToast } from "primevue/usetoast";
import { computed, onMounted } from "vue"; import { computed, inject, onMounted } from "vue";
import { router } from "@/main"; import { router } from "@/main";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
const { t } = useI18n({ useScope: "global" }); const { t } = useI18n({ useScope: "global" });
const toast = useToast(); const toast = useToast();
const domain = import.meta.env.SSR ? inject<string>("domain")! : window.location.hostname;
const domain = window.location.hostname;
const getLink = () => const getLink = () =>
"https://" + domain + "/api/feed?token=" + tokenStore().token; "https://" + domain + "/api/feed?token=" + tokenStore().token;
@@ -36,7 +36,7 @@ const show = () => {
severity: "info", severity: "info",
summary: t("calendarLink.copyToastSummary"), summary: t("calendarLink.copyToastSummary"),
detail: t("calendarLink.copyToastNotification"), detail: t("calendarLink.copyToastNotification"),
life: 3000, life: 3000
}); });
}; };
@@ -57,7 +57,7 @@ function copyToClipboard() {
severity: "error", severity: "error",
summary: t("calendarLink.copyToastError"), summary: t("calendarLink.copyToastError"),
detail: t("calendarLink.copyToastErrorDetail"), detail: t("calendarLink.copyToastErrorDetail"),
life: 3000, life: 3000
}); });
}); });
} }
@@ -65,14 +65,14 @@ function copyToClipboard() {
const forwardToGoogle = () => { const forwardToGoogle = () => {
window.open( window.open(
"https://calendar.google.com/calendar/u/0/r?cid=" + "https://calendar.google.com/calendar/u/0/r?cid=" +
encodeURI(getLink().replace("https://", "http://")), encodeURI(getLink().replace("https://", "http://"))
); );
}; };
const forwardToMicrosoft = () => { const forwardToMicrosoft = () => {
window.open( window.open(
"https://outlook.live.com/owa?path=/calendar/action/compose&rru=addsubscription&name=HTWK%20Kalender&url=" + "https://outlook.live.com/owa?path=/calendar/action/compose&rru=addsubscription&name=HTWK%20Kalender&url=" +
encodeURI(getLink()), encodeURI(getLink())
); );
}; };
@@ -80,18 +80,18 @@ const actions = computed(() => [
{ {
label: t("calendarLink.copyToClipboard"), label: t("calendarLink.copyToClipboard"),
icon: "pi pi-copy", icon: "pi pi-copy",
command: copyToClipboard, command: copyToClipboard
}, },
{ {
label: t("calendarLink.toGoogleCalendar"), label: t("calendarLink.toGoogleCalendar"),
icon: "pi pi-google", icon: "pi pi-google",
command: forwardToGoogle, command: forwardToGoogle
}, },
{ {
label: t("calendarLink.toMicrosoftCalendar"), label: t("calendarLink.toMicrosoftCalendar"),
icon: "pi pi-microsoft", icon: "pi pi-microsoft",
command: forwardToMicrosoft, command: forwardToMicrosoft
}, }
]); ]);
</script> </script>