From 8251c6f2d3154fe6f17ac2b476a6162ed348ec1c Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Mon, 3 Feb 2025 13:06:27 -0500 Subject: [PATCH] fix: only toast unread notifications, not archived ones --- .../notifications/notifications.service.ts | 10 ++++++---- web/components/Notifications/Sidebar.vue | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts b/api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts index f61169749..b9e96bb1b 100644 --- a/api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts +++ b/api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts @@ -103,10 +103,12 @@ export class NotificationsService { const notification = await this.loadNotificationFile(path, NotificationType[type]); this.increment(notification.importance, NotificationsService.overview[type.toLowerCase()]); - this.publishOverview(); - pubsub.publish(PUBSUB_CHANNEL.NOTIFICATION_ADDED, { - notificationAdded: notification, - }); + if (type === NotificationType.UNREAD) { + this.publishOverview(); + pubsub.publish(PUBSUB_CHANNEL.NOTIFICATION_ADDED, { + notificationAdded: notification, + }); + } } /** diff --git a/web/components/Notifications/Sidebar.vue b/web/components/Notifications/Sidebar.vue index 7003310d9..0aa1443f0 100644 --- a/web/components/Notifications/Sidebar.vue +++ b/web/components/Notifications/Sidebar.vue @@ -42,6 +42,12 @@ const { onResult: onNotificationAdded } = useSubscription(notificationAddedSubsc onNotificationAdded(({ data }) => { if (!data) return; const notif = useFragment(NOTIFICATION_FRAGMENT, data.notificationAdded); + if (notif.type !== NotificationType.Unread) return; + // probably smart to leave this log outside the if-block for the initial release + console.log('incoming notification', notif); + if (!globalThis.toast) { + return; + } const funcMapping: Record = { [Importance.Alert]: globalThis.toast.error, @@ -51,10 +57,12 @@ onNotificationAdded(({ data }) => { const toast = funcMapping[notif.importance]; const createOpener = () => ({ label: 'Open', onClick: () => location.assign(notif.link as string) }); - toast(notif.title, { - description: notif.subject, - action: notif.link ? createOpener() : undefined, - }); + requestAnimationFrame(() => + toast(notif.title, { + description: notif.subject, + action: notif.link ? createOpener() : undefined, + }) + ); }); const overview = computed(() => {