From 1204094bef2c7dc7a70fbceaeca99ad2168da3ff Mon Sep 17 00:00:00 2001 From: eti Date: Mon, 16 Nov 2026 22:01:26 +0100 Subject: [PATCH] web/notifications: add a refresh button to the panel and page Signed-off-by: eti --- .../notifications/NotificationBell.svelte | 10 ++++- .../NotificationToolbar.stories.svelte | 4 +- .../notifications/NotificationToolbar.svelte | 45 +++++++++++++++++-- web/src/routes/notifications/+page.svelte | 9 +++- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/web/src/lib/components/notifications/NotificationBell.svelte b/web/src/lib/components/notifications/NotificationBell.svelte index fc6563428..df57aaad8 100644 --- a/web/src/lib/components/notifications/NotificationBell.svelte +++ b/web/src/lib/components/notifications/NotificationBell.svelte @@ -55,6 +55,11 @@ .slice(0, PREVIEW_LIMIT) ); + let hasNotifications = $state(false); + $effect(() => { + if (previewLoad.data) hasNotifications = preview.length > 0; + }); + const dismiss = (event: MouseEvent & { currentTarget: HTMLAnchorElement }) => { const popover = event.currentTarget.closest("[popover]"); if (popover instanceof HTMLElement) popover.hidePopover(); @@ -113,11 +118,14 @@ 0} + {hasNotifications} preferences={false} + labels={false} onReadFilter={(filter) => (readFilter = filter)} onCategoryFilter={(filter) => (categoryFilter = filter)} onMarkAllRead={shared.markAllRead} + refreshing={previewLoad.loading} + onRefresh={() => previewLoad.run()} /> diff --git a/web/src/lib/components/notifications/NotificationToolbar.stories.svelte b/web/src/lib/components/notifications/NotificationToolbar.stories.svelte index 1235d8da4..bbd75c5e7 100644 --- a/web/src/lib/components/notifications/NotificationToolbar.stories.svelte +++ b/web/src/lib/components/notifications/NotificationToolbar.stories.svelte @@ -1,11 +1,13 @@ diff --git a/web/src/lib/components/notifications/NotificationToolbar.svelte b/web/src/lib/components/notifications/NotificationToolbar.svelte index ca4c0cb72..22881811c 100644 --- a/web/src/lib/components/notifications/NotificationToolbar.svelte +++ b/web/src/lib/components/notifications/NotificationToolbar.svelte @@ -4,6 +4,7 @@ import Cog from "$icon/cog"; import Glasses from "$icon/glasses"; import Inbox from "$icon/inbox"; + import RefreshCw from "$icon/refresh-cw"; import Button from "#lib/components/ui/Button.svelte"; import Segment from "#lib/components/ui/Segment.svelte"; import SegmentedControl from "#lib/components/ui/SegmentedControl.svelte"; @@ -14,9 +15,12 @@ categoryFilter?: CategoryFilter; hasNotifications?: boolean; preferences?: boolean; + labels?: boolean; + refreshing?: boolean; onReadFilter?: (filter: ReadFilter) => void; onCategoryFilter?: (filter: CategoryFilter) => void; onMarkAllRead?: () => void; + onRefresh?: () => void; } let { @@ -24,9 +28,12 @@ categoryFilter = "all", hasNotifications = true, preferences = true, + labels = true, + refreshing = false, onReadFilter, onCategoryFilter, - onMarkAllRead + onMarkAllRead, + onRefresh }: Props = $props(); const pageQuery = (read: ReadFilter, category: CategoryFilter) => @@ -36,8 +43,26 @@ resolve(`/notifications?${pageQuery(read, category)}` as "/"); const categories: CategoryFilter[] = ["all", "work", "social"]; + + let spinning = $state(false); + const refresh = () => { + spinning = true; + onRefresh?.(); + }; + const settle = () => { + if (!refreshing) spinning = false; + }; + const spinClass = "[&_svg]:motion-safe:animate-spin [&_svg]:motion-reduce:animate-pulse"; +{#snippet markAllReadLabel()} + +{/snippet} + +{#snippet refreshLabel()} + +{/snippet} +
onMarkAllRead?.()} aria-label="Mark all read" - > - - + children={labels ? markAllReadLabel : undefined} + /> + {/if} + + {#if onRefresh} +
diff --git a/web/src/routes/notifications/+page.svelte b/web/src/routes/notifications/+page.svelte index f55bb61b0..15f2c6cc4 100644 --- a/web/src/routes/notifications/+page.svelte +++ b/web/src/routes/notifications/+page.svelte @@ -43,6 +43,11 @@ ); const showSocial = $derived(social.length > 0); + + let hasNotifications = $state(false); + $effect(() => { + if (loaded.data) hasNotifications = visible.length > 0; + }); @@ -52,8 +57,10 @@ 0} + {hasNotifications} onMarkAllRead={shared.markAllRead} + refreshing={loaded.loading} + onRefresh={() => loaded.run()} /> -- knotmirror 0.0.1