From f69b30b5ba9abcce764e3d7fa77d1750856b70ef Mon Sep 17 00:00:00 2001 From: flfeders Date: Fri, 8 Nov 2024 20:17:56 +0100 Subject: [PATCH] Added Notifications Added Mentions in HistoryItems --- components/HistoryDisplay.vue | 28 +++++++- components/NotificationsSlideover.vue | 53 +++++++++++--- pages/communication/historyItems/index.vue | 83 ++++++++++++++++++++++ pages/index.vue | 8 ++- pages/plants/[mode]/[[id]].vue | 2 +- pages/profiles/show/[id].vue | 10 ++- 6 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 pages/communication/historyItems/index.vue diff --git a/components/HistoryDisplay.vue b/components/HistoryDisplay.vue index b1796d2..3b0f00a 100644 --- a/components/HistoryDisplay.vue +++ b/components/HistoryDisplay.vue @@ -69,6 +69,10 @@ setup() const addHistoryItemData = ref({ text: "", + config: { + type: type, + id: elementId + } }) const addHistoryItem = async () => { @@ -120,6 +124,29 @@ const addHistoryItem = async () => { if(error) { console.log(error) } else { + if(addHistoryItemData.value.text.includes("@")){ + let usernames = [...addHistoryItemData.value.text.matchAll(/@(\S*)/gm)] + + const {data:profiles} = await supabase.from("profiles").select("id,username") + + let notifications = usernames.map(i => { + let rawUsername = i[1] + + return { + tenant: dataStore.currentTenant, + profile: profiles.find(x => x.username === rawUsername).id, + initiatingProfile: dataStore.activeProfile.id, + title: "Sie wurden im Logbuch erwähnt", + link: `/${type}s/show/${elementId}`, + message: addHistoryItemData.value.text + } + }) + + console.log(notifications) + + const {error} = await supabase.from("notifications").insert(notifications) + } + addHistoryItemData.value = {} toast.add({title: "Eintrag erfolgreich erstellt"}) showAddHistoryItemModal.value = false @@ -188,7 +215,6 @@ const renderText = (text) => { -
-import { formatTimeAgo } from '@vueuse/core' -import type { Notification } from '~/types' + diff --git a/pages/communication/historyItems/index.vue b/pages/communication/historyItems/index.vue new file mode 100644 index 0000000..968cf1c --- /dev/null +++ b/pages/communication/historyItems/index.vue @@ -0,0 +1,83 @@ + + + + + \ No newline at end of file diff --git a/pages/index.vue b/pages/index.vue index 70e22a2..b9e1bd3 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -5,7 +5,7 @@