From 61790ed96cb1dd17a9d0fb42ca05cb11ae6eb1bf Mon Sep 17 00:00:00 2001 From: Vargha Csongor Date: Mon, 10 Mar 2025 23:10:12 +0100 Subject: [PATCH] add theme selector --- app/src/hooks.server.ts | 17 ++++++++- app/src/lib/theme-select.svelte | 58 +++++++++++++++++++++++++++++++ app/src/lib/themes.ts | 1 + app/src/routes/login/+page.svelte | 17 +++++++-- 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 app/src/lib/theme-select.svelte create mode 100644 app/src/lib/themes.ts diff --git a/app/src/hooks.server.ts b/app/src/hooks.server.ts index b01aa8c..70ab421 100644 --- a/app/src/hooks.server.ts +++ b/app/src/hooks.server.ts @@ -1,4 +1,5 @@ import type { Handle } from '@sveltejs/kit'; +import { themes } from '$lib/themes' import { i18n } from '$lib/i18n'; import { validateSessionToken, setSessionTokenCookie, deleteSessionTokenCookie } from "$lib/server/session"; import { sequence } from "@sveltejs/kit/hooks"; @@ -29,4 +30,18 @@ const authHandle: Handle = async ({ event, resolve }) => { return resolve(event); }; -export const handle: Handle = sequence(handleParaglide, authHandle); \ No newline at end of file +const themeHandler: Handle = async ({ event, resolve }) => { + const theme = event.cookies.get('theme') + + if (!theme || !themes.includes(theme)) { + return await resolve(event) + } + + return await resolve(event, { + transformPageChunk: ({ html }) => { + return html.replace('data-theme=""', `data-theme="${theme}"`) + }, + }) +} + +export const handle: Handle = sequence(handleParaglide, authHandle,themeHandler); \ No newline at end of file diff --git a/app/src/lib/theme-select.svelte b/app/src/lib/theme-select.svelte new file mode 100644 index 0000000..3d36b52 --- /dev/null +++ b/app/src/lib/theme-select.svelte @@ -0,0 +1,58 @@ + + + diff --git a/app/src/lib/themes.ts b/app/src/lib/themes.ts new file mode 100644 index 0000000..5fe290d --- /dev/null +++ b/app/src/lib/themes.ts @@ -0,0 +1 @@ +export const themes = ['light', 'dark','coffee', 'cyberpunk', 'synthwave', 'retro', 'dracula']; \ No newline at end of file diff --git a/app/src/routes/login/+page.svelte b/app/src/routes/login/+page.svelte index 1247599..872483b 100644 --- a/app/src/routes/login/+page.svelte +++ b/app/src/routes/login/+page.svelte @@ -1,6 +1,8 @@ @@ -10,14 +12,23 @@
+
+ {family_tree()} +

{sign_in()}

- Provident cupiditate voluptatem et in. Quaerat fugiat ut assumenda excepturi exercitationem - quasi. In deleniti eaque aut repudiandae et a id nisi. + {site_intro()}

{sign_in()}
+
+ +
+
\ No newline at end of file