From ebbfb6b48e343d3abb65a0ec856233f96aee68c4 Mon Sep 17 00:00:00 2001 From: survellow <59056368+survellow@users.noreply.github.com> Date: Wed, 14 Aug 2024 23:53:07 +0200 Subject: [PATCH] feat:#17 add share button on calendar link page --- frontend/src/components/CalendarLink.vue | 92 ++++++++++++++++++------ frontend/src/i18n/translations/de.json | 9 ++- frontend/src/i18n/translations/en.json | 9 ++- frontend/src/i18n/translations/ja.json | 9 ++- 4 files changed, 94 insertions(+), 25 deletions(-) diff --git a/frontend/src/components/CalendarLink.vue b/frontend/src/components/CalendarLink.vue index cf3d40c..6ab90c4 100644 --- a/frontend/src/components/CalendarLink.vue +++ b/frontend/src/components/CalendarLink.vue @@ -84,28 +84,76 @@ const forwardToHTWKalendar = () => { }); }; -const actions = computed(() => [ - { - label: t("calendarLink.copyToClipboard"), - icon: "pi pi-copy", - command: copyToClipboard, - }, - { - label: t("calendarLink.toGoogleCalendar"), - icon: "pi pi-google", - command: forwardToGoogle, - }, - { - label: t("calendarLink.toMicrosoftCalendar"), - icon: "pi pi-microsoft", - command: forwardToMicrosoft, - }, - { - label: t("calendarLink.toHTWKalendar"), - icon: "pi pi-home", - command: forwardToHTWKalendar, - }, -]); +const shareLink = () => { + if (typeof navigator.share === 'function' && navigator.canShare()) { + navigator + .share({ + title: t("calendarLink.shareTitle"), + text: t("calendarLink.shareText") + getLink(), + url: "https://" + domain + "/", + }) + .then(() => { + toast.add({ + severity: "info", + summary: t("calendarLink.shareToastSummary"), + detail: t("calendarLink.shareToastNotification"), + life: 3000, + }); + }) + .catch(() => { + toast.add({ + severity: "error", + summary: t("calendarLink.shareToastError"), + detail: t("calendarLink.shareToastErrorDetail"), + life: 3000, + }); + }); + } else { + toast.add({ + severity: "error", + summary: t("calendarLink.shareToastError"), + detail: t("calendarLink.shareToastErrorDetail"), + life: 3000, + }); + } +}; + +const actions = computed(() => { + var actionList = [ + { + label: t("calendarLink.copyToClipboard"), + icon: "pi pi-copy", + command: copyToClipboard, + }, + { + label: t("calendarLink.toGoogleCalendar"), + icon: "pi pi-google", + command: forwardToGoogle, + }, + { + label: t("calendarLink.toMicrosoftCalendar"), + icon: "pi pi-microsoft", + command: forwardToMicrosoft, + }, + { + label: t("calendarLink.toHTWKalendar"), + icon: "pi pi-home", + command: forwardToHTWKalendar, + } + ]; + + if (typeof navigator.share === 'function' && navigator.canShare()) { + actionList.push({ + label: t("calendarLink.share"), + icon: "pi pi-share-alt", + command: shareLink, + }); + } + + return actionList; +} + +);