From 069f38a313fdeb7d2da57d51a179700b066e8709 Mon Sep 17 00:00:00 2001 From: eewing Date: Tue, 17 Feb 2026 10:31:57 -0600 Subject: [PATCH] Implement user settings and dark mode toggle in layout component - Added functionality to toggle dark mode based on user preferences, with state management and API integration for saving settings. - Introduced a user avatar display with initials fallback and a dropdown menu for logout and dark mode options. - Enhanced layout structure to conditionally render the header based on user authentication status. --- .../ui/avatar/avatar-fallback.svelte | 17 ++++ .../components/ui/avatar/avatar-image.svelte | 17 ++++ src/lib/components/ui/avatar/avatar.svelte | 19 ++++ src/lib/components/ui/avatar/index.ts | 13 +++ src/lib/components/ui/switch/index.ts | 7 ++ src/lib/components/ui/switch/switch.svelte | 29 ++++++ src/routes/+layout.server.ts | 7 ++ src/routes/+layout.svelte | 90 ++++++++++++++++++- src/routes/api/user/settings/+server.ts | 24 +++++ src/routes/logout/+server.ts | 11 +++ 10 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/ui/avatar/avatar-fallback.svelte create mode 100644 src/lib/components/ui/avatar/avatar-image.svelte create mode 100644 src/lib/components/ui/avatar/avatar.svelte create mode 100644 src/lib/components/ui/avatar/index.ts create mode 100644 src/lib/components/ui/switch/index.ts create mode 100644 src/lib/components/ui/switch/switch.svelte create mode 100644 src/routes/+layout.server.ts create mode 100644 src/routes/api/user/settings/+server.ts create mode 100644 src/routes/logout/+server.ts diff --git a/src/lib/components/ui/avatar/avatar-fallback.svelte b/src/lib/components/ui/avatar/avatar-fallback.svelte new file mode 100644 index 0000000..249d4a4 --- /dev/null +++ b/src/lib/components/ui/avatar/avatar-fallback.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/avatar/avatar-image.svelte b/src/lib/components/ui/avatar/avatar-image.svelte new file mode 100644 index 0000000..2bb9db4 --- /dev/null +++ b/src/lib/components/ui/avatar/avatar-image.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/avatar/avatar.svelte b/src/lib/components/ui/avatar/avatar.svelte new file mode 100644 index 0000000..e37214d --- /dev/null +++ b/src/lib/components/ui/avatar/avatar.svelte @@ -0,0 +1,19 @@ + + + diff --git a/src/lib/components/ui/avatar/index.ts b/src/lib/components/ui/avatar/index.ts new file mode 100644 index 0000000..d06457b --- /dev/null +++ b/src/lib/components/ui/avatar/index.ts @@ -0,0 +1,13 @@ +import Root from "./avatar.svelte"; +import Image from "./avatar-image.svelte"; +import Fallback from "./avatar-fallback.svelte"; + +export { + Root, + Image, + Fallback, + // + Root as Avatar, + Image as AvatarImage, + Fallback as AvatarFallback, +}; diff --git a/src/lib/components/ui/switch/index.ts b/src/lib/components/ui/switch/index.ts new file mode 100644 index 0000000..f5533db --- /dev/null +++ b/src/lib/components/ui/switch/index.ts @@ -0,0 +1,7 @@ +import Root from "./switch.svelte"; + +export { + Root, + // + Root as Switch, +}; diff --git a/src/lib/components/ui/switch/switch.svelte b/src/lib/components/ui/switch/switch.svelte new file mode 100644 index 0000000..80661fd --- /dev/null +++ b/src/lib/components/ui/switch/switch.svelte @@ -0,0 +1,29 @@ + + + + + diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts new file mode 100644 index 0000000..7d98a1b --- /dev/null +++ b/src/routes/+layout.server.ts @@ -0,0 +1,7 @@ +import type { LayoutServerLoad } from './$types'; + +export const load: LayoutServerLoad = async ({ locals }) => { + return { + user: locals.user ? structuredClone(locals.user) : null + }; +}; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 35c1c75..8a07009 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,13 +1,56 @@