From a2d25e03861ba33caf790b5abc85559f6342de99 Mon Sep 17 00:00:00 2001 From: frag223 Date: Sat, 10 Jan 2026 14:53:35 +1100 Subject: [PATCH 1/3] update logic to only manage unread notifications. --- .../lib/watchtower/notifications.svelte.ts | 31 +++++++------------ .../routes/(orgs)/notifications/+page.svelte | 18 ++++++----- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/frontend/src/lib/watchtower/notifications.svelte.ts b/frontend/src/lib/watchtower/notifications.svelte.ts index 0eb201e..0149f3b 100644 --- a/frontend/src/lib/watchtower/notifications.svelte.ts +++ b/frontend/src/lib/watchtower/notifications.svelte.ts @@ -3,21 +3,21 @@ import { STALE_TIMEOUT_MINUTES } from "$lib/watchtower/types"; import { GetUnreadNotifications, MarkNotificationAsRead } from "$lib/wailsjs/go/watchtower/Service"; export class NotificationsService { - readonly #notifications: notifications.Notification[]; + readonly #unread: notifications.Notification[]; #lastSync?: number; constructor() { - this.#notifications = $state([]); + this.#unread = $state([]); } /** * Retrieves the unread notifications for the user. */ async getUnread() { if (this.isStale()) { - await this.forceGetNotifications(); + await this.forceGetUnread(); } - return this.#notifications; + return this.#unread; } /** @@ -25,19 +25,12 @@ export class NotificationsService { */ async markAsRead(id: number) { await MarkNotificationAsRead(id); - const idx = this.#notifications.findIndex((n) => n.id === id); + const idx = this.#unread.findIndex((n) => n.id === id); if (idx < 0) { return; } - this.#notifications.splice( - idx, - 1, - new notifications.Notification({ - ...this.#notifications[idx], - status: "read" - }) - ); + this.#unread.splice(idx, 1); } /** @@ -49,22 +42,22 @@ export class NotificationsService { await this.markAsRead(notification.id); } - await this.forceGetNotifications(); + await this.forceGetUnread(); } /** * Forces the retrieval of unread notifications and updates the internal state with the fetched notifications. */ - private async forceGetNotifications() { + private async forceGetUnread() { const notifications = (await GetUnreadNotifications()) ?? []; - this.updateInternalNotifications(notifications); + this.updateInternalUnread(notifications); } /** * Updates the internal notifications by replacing the current list with the provided notifications array. */ - private updateInternalNotifications(notifications: notifications.Notification[]) { - this.#notifications.splice(0, this.#notifications.length, ...notifications); + private updateInternalUnread(notifications: notifications.Notification[]) { + this.#unread.splice(0, this.#unread.length, ...notifications); this.#lastSync = Date.now(); } @@ -73,7 +66,7 @@ export class NotificationsService { * and the presence of notifications. */ private isStale() { - if (!this.#lastSync || this.#notifications.length === 0) { + if (!this.#lastSync || this.#unread.length === 0) { return true; } diff --git a/frontend/src/routes/(orgs)/notifications/+page.svelte b/frontend/src/routes/(orgs)/notifications/+page.svelte index a4a1263..ba99005 100644 --- a/frontend/src/routes/(orgs)/notifications/+page.svelte +++ b/frontend/src/routes/(orgs)/notifications/+page.svelte @@ -11,17 +11,19 @@ import { resolve } from "$app/paths"; import { SimpleFilter } from "$lib/hooks/filters.svelte"; import { BaseInput } from "$components/base_input"; + import { notifications } from "$lib/wailsjs/go/models"; const { data } = $props(); - let notifications = $derived(data.notifications); + let unreadNotifications = $derived(data.notifications); let searchState = $state(""); - const searchFilter = $derived( - new SimpleFilter(notifications, (item) => { - return item.content.toLowerCase().includes(searchState.toLowerCase()); - }) - ); + + function applySearchFilter(notification: notifications.Notification) { + return notification.content.toLowerCase().includes(searchState.toLowerCase()); + } + + const searchFilter = $derived(new SimpleFilter(unreadNotifications, applySearchFilter)); async function markAllAsRead() { await notificationSvc.markAllAsRead(); @@ -42,7 +44,7 @@
- {#if notifications.length > 0} + {#if searchFilter.data.length > 0}
- {#if notifications.length === 0} + {#if unreadNotifications.length === 0} Date: Sat, 10 Jan 2026 15:04:09 +1100 Subject: [PATCH 2/3] adding slide transitions --- .../routes/(orgs)/notifications/+page.svelte | 86 ++++++++++--------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/frontend/src/routes/(orgs)/notifications/+page.svelte b/frontend/src/routes/(orgs)/notifications/+page.svelte index ba99005..a802236 100644 --- a/frontend/src/routes/(orgs)/notifications/+page.svelte +++ b/frontend/src/routes/(orgs)/notifications/+page.svelte @@ -1,4 +1,6 @@