Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode fix #59

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
%sveltekit.head%
<script>
var ui_theme = localStorage.getItem("ui_theme");
if (ui_theme && ui_theme !== "default") {
document.querySelector("html").dataset.theme = ui_theme;
scosman marked this conversation as resolved.
Show resolved Hide resolved
}
</script>
</head>
<body
data-sveltekit-preload-data="hover"
Expand Down
26 changes: 5 additions & 21 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ 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"

const setSession: Handle = async ({ event, resolve }) => {
export const handle: Handle = async ({ event, resolve }) => {
event.locals.supabase = createSupabaseServerClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
event,
})

event.locals.supabaseServiceRole = createClient(
PUBLIC_SUPABASE_URL,
PRIVATE_SUPABASE_SERVICE_ROLE,
{ auth: { persistSession: false } },
PUBLIC_SUPABASE_URL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to run prettier, formatting is breaking CI.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

PRIVATE_SUPABASE_SERVICE_ROLE,
{ auth: { persistSession: false } },
)

/**
Expand All @@ -37,19 +36,4 @@ const setSession: Handle = async ({ event, resolve }) => {
return name === "content-range"
},
})
}

const insertTheme: Handle = async ({ event, resolve }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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)
}
6 changes: 5 additions & 1 deletion src/routes/(admin)/account/(menu)/theme.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
</script>

Expand Down
Loading