From 6e6f09dba011c436b5c4429759b44dfbf3a82a7f Mon Sep 17 00:00:00 2001 From: DecDuck Date: Sat, 16 Nov 2024 19:41:19 +1100 Subject: [PATCH] feat(notifications): added notification system w/ interwoven refactoring --- .../{DocsSidebar.vue => Docs/Sidebar.vue} | 0 .../SidebarNavItem.vue} | 0 components/HeaderWidget.vue | 17 ---- components/Notification.vue | 57 ++++++++++++ components/PanelWidget.vue | 2 +- components/UserHeader.vue | 82 +++++++++++------ .../UserHeader/NotificationWidgetPanel.vue | 43 +++++++++ .../UserWidget.vue} | 7 +- components/UserHeader/Widget.vue | 37 ++++++++ composables/notifications.ts | 12 +++ composables/types.d.ts | 2 +- .../migration.sql | 18 ++++ .../migration.sql | 2 + prisma/schema/user.prisma | 20 ++++- .../api/v1/notifications/[id]/index.delete.ts | 28 ++++++ server/api/v1/notifications/[id]/index.get.ts | 28 ++++++ server/api/v1/notifications/[id]/read.post.ts | 31 +++++++ server/api/v1/notifications/index.get.ts | 17 ++++ server/api/v1/notifications/readall.post.ts | 17 ++++ server/api/v1/notifications/ws.get.ts | 42 +++++++++ server/api/v1/task/index.get.ts | 4 +- server/internal/notifications/index.ts | 88 +++++++++++++++++++ 22 files changed, 498 insertions(+), 56 deletions(-) rename components/{DocsSidebar.vue => Docs/Sidebar.vue} (100%) rename components/{DocsSidebarNavItem.vue => Docs/SidebarNavItem.vue} (100%) delete mode 100644 components/HeaderWidget.vue create mode 100644 components/Notification.vue create mode 100644 components/UserHeader/NotificationWidgetPanel.vue rename components/{HeaderUserWidget.vue => UserHeader/UserWidget.vue} (94%) create mode 100644 components/UserHeader/Widget.vue create mode 100644 composables/notifications.ts create mode 100644 prisma/migrations/20241116053120_add_notifications/migration.sql create mode 100644 prisma/migrations/20241116054212_add_created_time_stamp_to_notifications/migration.sql create mode 100644 server/api/v1/notifications/[id]/index.delete.ts create mode 100644 server/api/v1/notifications/[id]/index.get.ts create mode 100644 server/api/v1/notifications/[id]/read.post.ts create mode 100644 server/api/v1/notifications/index.get.ts create mode 100644 server/api/v1/notifications/readall.post.ts create mode 100644 server/api/v1/notifications/ws.get.ts create mode 100644 server/internal/notifications/index.ts diff --git a/components/DocsSidebar.vue b/components/Docs/Sidebar.vue similarity index 100% rename from components/DocsSidebar.vue rename to components/Docs/Sidebar.vue diff --git a/components/DocsSidebarNavItem.vue b/components/Docs/SidebarNavItem.vue similarity index 100% rename from components/DocsSidebarNavItem.vue rename to components/Docs/SidebarNavItem.vue diff --git a/components/HeaderWidget.vue b/components/HeaderWidget.vue deleted file mode 100644 index 861f5d05..00000000 --- a/components/HeaderWidget.vue +++ /dev/null @@ -1,17 +0,0 @@ - - - \ No newline at end of file diff --git a/components/Notification.vue b/components/Notification.vue new file mode 100644 index 00000000..6ca05593 --- /dev/null +++ b/components/Notification.vue @@ -0,0 +1,57 @@ + + + diff --git a/components/PanelWidget.vue b/components/PanelWidget.vue index be7ba0f0..5022563f 100644 --- a/components/PanelWidget.vue +++ b/components/PanelWidget.vue @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/components/UserHeader.vue b/components/UserHeader.vue index fb13efb7..a8afc0d4 100644 --- a/components/UserHeader.vue +++ b/components/UserHeader.vue @@ -21,15 +21,39 @@
    -
  1. - - - +
  2. + + +
  3. - + +
  4. + + + + + + + + + + + + + +
  5. +
@@ -41,7 +65,7 @@
- +
@@ -156,9 +184,11 @@ import { DialogPanel, TransitionChild, TransitionRoot, + Menu, + MenuButton, + MenuItems, } from "@headlessui/vue"; -import type { NavigationItem, QuickActionNav } from "../composables/types"; -import HeaderWidget from "./HeaderWidget.vue"; +import type { NavigationItem } from "../composables/types"; import { Bars3Icon } from "@heroicons/vue/24/outline"; import { XMarkIcon } from "@heroicons/vue/24/solid"; @@ -189,16 +219,10 @@ const navigation: Array = [ const currentPageIndex = useCurrentNavigationIndex(navigation); -const quickActions: Array = [ - { - icon: UserGroupIcon, - action: async () => {}, - }, - { - icon: BellIcon, - action: async () => {}, - }, -]; +const notifications = useNotifications(); +const unreadNotifications = computed(() => + notifications.value.filter((e) => !e.read) +); const sidebarOpen = ref(false); router.afterEach(() => (sidebarOpen.value = false)); diff --git a/components/UserHeader/NotificationWidgetPanel.vue b/components/UserHeader/NotificationWidgetPanel.vue new file mode 100644 index 00000000..b0addf4f --- /dev/null +++ b/components/UserHeader/NotificationWidgetPanel.vue @@ -0,0 +1,43 @@ + + + diff --git a/components/HeaderUserWidget.vue b/components/UserHeader/UserWidget.vue similarity index 94% rename from components/HeaderUserWidget.vue rename to components/UserHeader/UserWidget.vue index 54cd21eb..de99c97e 100644 --- a/components/HeaderUserWidget.vue +++ b/components/UserHeader/UserWidget.vue @@ -1,7 +1,7 @@