From 4edc091ac622f4d0622863afbc3af4dd88af2796 Mon Sep 17 00:00:00 2001 From: NDruce Date: Thu, 18 Apr 2024 19:21:34 +0300 Subject: [PATCH 1/2] Dark Mode fix --- src/app.html | 6 +++++ src/hooks.server.ts | 26 ++++--------------- .../(admin)/account/(menu)/theme.svelte | 6 ++++- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/app.html b/src/app.html index 9a0f5b64..9b05d1e6 100644 --- a/src/app.html +++ b/src/app.html @@ -5,6 +5,12 @@ %sveltekit.head% + { +export const handle: Handle = async ({ event, resolve }) => { event.locals.supabase = createSupabaseServerClient({ supabaseUrl: PUBLIC_SUPABASE_URL, supabaseKey: PUBLIC_SUPABASE_ANON_KEY, @@ -17,9 +16,9 @@ const setSession: Handle = async ({ event, resolve }) => { }) event.locals.supabaseServiceRole = createClient( - PUBLIC_SUPABASE_URL, - PRIVATE_SUPABASE_SERVICE_ROLE, - { auth: { persistSession: false } }, + PUBLIC_SUPABASE_URL, + PRIVATE_SUPABASE_SERVICE_ROLE, + { auth: { persistSession: false } }, ) /** @@ -37,19 +36,4 @@ const setSession: Handle = async ({ event, resolve }) => { return name === "content-range" }, }) -} - -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) +} \ No newline at end of file diff --git a/src/routes/(admin)/account/(menu)/theme.svelte b/src/routes/(admin)/account/(menu)/theme.svelte index c0601909..48d0033e 100644 --- a/src/routes/(admin)/account/(menu)/theme.svelte +++ b/src/routes/(admin)/account/(menu)/theme.svelte @@ -10,7 +10,11 @@ ? "dark" : "default" document.querySelector("html")?.setAttribute("data-theme", theme) - document.cookie = `theme=${theme}; expires=Thu, 1 Dec 2050 12:00:00 UTC` + if (theme !== "default") { + localStorage.setItem("ui_theme", theme) + } else { + localStorage.removeItem("ui_theme") + } } From 33ad12bf306be12716862f1ea80607d0679df804 Mon Sep 17 00:00:00 2001 From: NDruce Date: Fri, 19 Apr 2024 19:50:06 +0300 Subject: [PATCH 2/2] Prettier --- src/app.html | 4 ++-- src/hooks.server.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app.html b/src/app.html index 9b05d1e6..ab56033b 100644 --- a/src/app.html +++ b/src/app.html @@ -6,9 +6,9 @@ %sveltekit.head% diff --git a/src/hooks.server.ts b/src/hooks.server.ts index f6815b4b..76c2b8a7 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -16,9 +16,9 @@ export const handle: Handle = async ({ event, resolve }) => { }) event.locals.supabaseServiceRole = createClient( - PUBLIC_SUPABASE_URL, - PRIVATE_SUPABASE_SERVICE_ROLE, - { auth: { persistSession: false } }, + PUBLIC_SUPABASE_URL, + PRIVATE_SUPABASE_SERVICE_ROLE, + { auth: { persistSession: false } }, ) /** @@ -36,4 +36,4 @@ export const handle: Handle = async ({ event, resolve }) => { return name === "content-range" }, }) -} \ No newline at end of file +}