From 0754d62d0e02dde7391a5795d24968807270be53 Mon Sep 17 00:00:00 2001 From: Zias van Nes Date: Sat, 8 Nov 2025 14:27:21 +0100 Subject: [PATCH] fix:push notification UI, settings and API Introduce NotificationManager, NotificationPrompt, NotificationSettings, NotificationSettingsSheet and integrate into the profile panel. Add server GET/POST endpoints for notification preferences. Add lucide-svelte dependency and update CSP connect-src to allow fcm.googleapis.com and android.googleapis.com --- package.json | 1 + src/hooks.server.ts | 2 +- src/lib/components/NotificationManager.svelte | 122 +++-- src/lib/components/NotificationPrompt.svelte | 173 +++++++ .../components/NotificationSettings.svelte | 469 ++++++++++++++++++ .../NotificationSettingsSheet.svelte | 36 ++ src/lib/components/ProfilePanel.svelte | 28 ++ src/lib/index.ts | 4 + .../api/notifications/preferences/+server.ts | 93 ++++ 9 files changed, 887 insertions(+), 41 deletions(-) create mode 100644 src/lib/components/NotificationPrompt.svelte create mode 100644 src/lib/components/NotificationSettings.svelte create mode 100644 src/lib/components/NotificationSettingsSheet.svelte create mode 100644 src/routes/api/notifications/preferences/+server.ts diff --git a/package.json b/package.json index 98d74ff..df063f4 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@node-rs/argon2": "^2.0.2", "@sveltejs/adapter-vercel": "^5.10.2", "arctic": "^3.7.0", + "lucide-svelte": "^0.553.0", "nanoid": "^5.1.6", "postgres": "^3.4.5", "sharp": "^0.34.4", diff --git a/src/hooks.server.ts b/src/hooks.server.ts index ece53f6..d58a3c5 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -52,7 +52,7 @@ export const handle: Handle = async ({ event, resolve }) => { "font-src 'self' fonts.gstatic.com; " + "img-src 'self' data: blob: *.openstreetmap.org *.tile.openstreetmap.org *.r2.cloudflarestorage.com *.r2.dev; " + "media-src 'self' *.r2.cloudflarestorage.com *.r2.dev; " + - "connect-src 'self' *.openstreetmap.org; " + + "connect-src 'self' *.openstreetmap.org https://fcm.googleapis.com https://android.googleapis.com; " + "frame-ancestors 'none'; " + "base-uri 'self'; " + "form-action 'self';" diff --git a/src/lib/components/NotificationManager.svelte b/src/lib/components/NotificationManager.svelte index 4a08281..81ac3f3 100644 --- a/src/lib/components/NotificationManager.svelte +++ b/src/lib/components/NotificationManager.svelte @@ -1,32 +1,33 @@ + +{#if showPrompt} + +{/if} diff --git a/src/lib/components/NotificationPrompt.svelte b/src/lib/components/NotificationPrompt.svelte new file mode 100644 index 0000000..2ac216f --- /dev/null +++ b/src/lib/components/NotificationPrompt.svelte @@ -0,0 +1,173 @@ + + +
+
+
+ +
+
+

Enable Notifications

+

Stay updated when friends like or comment on your finds

+
+
+ + +
+
+
+ + diff --git a/src/lib/components/NotificationSettings.svelte b/src/lib/components/NotificationSettings.svelte new file mode 100644 index 0000000..2281d44 --- /dev/null +++ b/src/lib/components/NotificationSettings.svelte @@ -0,0 +1,469 @@ + + +
+ {#if isLoading} +
Loading preferences...
+ {:else} + + {#if browserPermission !== 'granted'} +
+
+ {#if browserPermission === 'denied'} + Browser notifications blocked +

+ Please enable notifications in your browser settings to receive push notifications +

+ {:else} + Browser permission required +

Enable browser notifications to receive push notifications

+ {/if} +
+ {#if browserPermission === 'default'} + + {/if} +
+ {/if} + +
+ +
+
+

Push Notifications

+

Enable or disable all push notifications

+
+ +
+ +
+ + +
+
+

Friend Requests

+

Get notified when someone sends you a friend request

+
+ +
+ + +
+
+

Friend Request Accepted

+

Get notified when someone accepts your friend request

+
+ +
+ + +
+
+

Find Likes

+

Get notified when someone likes your find

+
+ +
+ + +
+
+

Find Comments

+

Get notified when someone comments on your find

+
+ +
+
+ {/if} +
+ + diff --git a/src/lib/components/NotificationSettingsSheet.svelte b/src/lib/components/NotificationSettingsSheet.svelte new file mode 100644 index 0000000..40bad82 --- /dev/null +++ b/src/lib/components/NotificationSettingsSheet.svelte @@ -0,0 +1,36 @@ + + + + + + Notifications + Manage your notification preferences + +
+ +
+
+
+ + diff --git a/src/lib/components/ProfilePanel.svelte b/src/lib/components/ProfilePanel.svelte index 872a6c9..73f67b0 100644 --- a/src/lib/components/ProfilePanel.svelte +++ b/src/lib/components/ProfilePanel.svelte @@ -10,6 +10,7 @@ import { Skeleton } from './skeleton'; import ProfilePicture from './ProfilePicture.svelte'; import ProfilePictureSheet from './ProfilePictureSheet.svelte'; + import NotificationSettingsSheet from './NotificationSettingsSheet.svelte'; interface Props { username: string; @@ -21,6 +22,7 @@ let { username, id, profilePictureUrl, loading = false }: Props = $props(); let showProfilePictureSheet = $state(false); + let showNotificationSettingsSheet = $state(false); function openProfilePictureSheet() { showProfilePictureSheet = true; @@ -29,6 +31,14 @@ function closeProfilePictureSheet() { showProfilePictureSheet = false; } + + function openNotificationSettingsSheet() { + showNotificationSettingsSheet = true; + } + + function closeNotificationSettingsSheet() { + showNotificationSettingsSheet = false; + } @@ -74,6 +84,10 @@ Friends + + Notifications + +