diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index eabf47d..6b0324c 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -7,6 +7,7 @@ import NotificationSettings from './components/NotificationSettings.svelte'; import { replaceState } from '$app/navigation'; import { pushNotificationManager } from '$lib/client/PushNotificationManager'; + import type { NotificationState } from '$lib/client/PushNotificationManager'; let items = $state([]); let loading = $state(true); @@ -16,6 +17,7 @@ let connectionStatus = $state<'connecting' | 'connected' | 'disconnected'>('disconnected'); let lastPing = $state(null); let hasAttemptedAutoSubscribe = $state(false); + let notificationViewModel = $state(null); // Get highlighted item ID from URL params (when redirected from Share page) let highlightId = $derived($page.url.searchParams.get('highlight')); @@ -37,11 +39,16 @@ return items.filter(item => item.status === filter); }); + let unsubscribeNotifications: (() => void) | undefined; + onMount(async () => { await loadQueueItems(); if (browser) { startSSEConnection(); setupAutoSubscribe(); + unsubscribeNotifications = pushNotificationManager.onStateChange((newState) => { + notificationViewModel = newState; + }); } }); @@ -51,6 +58,8 @@ eventSource.close(); connectionStatus = 'disconnected'; } + // Add notification state cleanup + unsubscribeNotifications?.(); }); async function loadQueueItems() { @@ -282,25 +291,29 @@ - - - - - - Add Recipe URL - + + {#if items.length > 0} + + + + + + {/if} @@ -364,28 +377,53 @@ {/if} -
+
- -
-
-
- - {connectionStatus === 'connected' ? 'Live updates' : - connectionStatus === 'connecting' ? 'Connecting...' : - 'Disconnected'} - - {#if lastPing} - - ({new Date(lastPing).toLocaleTimeString()}) - - {/if} + +
+
+ + + + +
+
+