diff --git a/src/app.html b/src/app.html index 101c87ba..9a0f5b64 100644 --- a/src/app.html +++ b/src/app.html @@ -1,5 +1,5 @@ - +
diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 76c2b8a7..f222db69 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -7,8 +7,9 @@ import { PRIVATE_SUPABASE_SERVICE_ROLE } from "$env/static/private" import { createSupabaseServerClient } from "@supabase/auth-helpers-sveltekit" import { createClient } from "@supabase/supabase-js" import type { Handle } from "@sveltejs/kit" +import { sequence } from "@sveltejs/kit/hooks" -export const handle: Handle = async ({ event, resolve }) => { +const setSession: Handle = async ({ event, resolve }) => { event.locals.supabase = createSupabaseServerClient({ supabaseUrl: PUBLIC_SUPABASE_URL, supabaseKey: PUBLIC_SUPABASE_ANON_KEY, @@ -37,3 +38,18 @@ export const handle: Handle = async ({ event, resolve }) => { }, }) } + +const insertTheme: Handle = async ({ event, resolve }) => { + const theme = event.cookies.get("theme") + + return await resolve(event, { + transformPageChunk: ({ html }) => { + if (theme) { + html = html.replace('data-theme="default"', `data-theme="${theme}"`) + } + return html + }, + }) +} + +export const handle = sequence(setSession, insertTheme) diff --git a/src/routes/(admin)/account/(menu)/+layout.svelte b/src/routes/(admin)/account/(menu)/+layout.svelte index 7b652d7b..fe51fcd7 100644 --- a/src/routes/(admin)/account/(menu)/+layout.svelte +++ b/src/routes/(admin)/account/(menu)/+layout.svelte @@ -2,6 +2,7 @@ import "../../../../app.css" import { writable } from "svelte/store" import { setContext } from "svelte" + import Theme from "./theme.svelte" const adminSectionStore = writable("") setContext("adminSection", adminSectionStore) @@ -135,7 +136,10 @@