tangled
alpha
login
or
join now
finxol.io
/
bookmarker
0
fork
atom
A very simple bookmarking webapp
bookmarker.finxol.deno.net/
0
fork
atom
overview
issues
pulls
pipelines
fix: set theme on initial load
finxol.io
1 month ago
993ac1a5
a52f68bf
verified
This commit was signed with the committer's
known signature
.
finxol.io
SSH Key Fingerprint:
SHA256:olFE3asYdoBMScuJOt60UxXdJ0RFdGv5kVKrdOtIcPI=
1/1
deploy.yaml
success
9s
+25
-18
3 changed files
expand all
collapse all
unified
split
src
components
ThemeSwitcher.tsx
routes
__root.tsx
utils
theme.ts
+1
-18
src/components/ThemeSwitcher.tsx
reviewed
···
1
1
import { createEffect, createSignal, onCleanup, onMount } from "solid-js"
2
2
import { MoonIcon, SunIcon } from "lucide-solid"
3
3
-
4
4
-
type Theme = "light" | "dark"
5
5
-
6
6
-
const STORAGE_KEY = "theme"
7
7
-
8
8
-
function getSystemTheme(): Theme {
9
9
-
return window.matchMedia("(prefers-color-scheme: dark)").matches
10
10
-
? "dark"
11
11
-
: "light"
12
12
-
}
13
13
-
14
14
-
function getInitialTheme(): Theme {
15
15
-
const stored = localStorage.getItem(STORAGE_KEY)
16
16
-
if (stored === "light" || stored === "dark") {
17
17
-
return stored
18
18
-
}
19
19
-
return getSystemTheme()
20
20
-
}
3
3
+
import { getInitialTheme, STORAGE_KEY, Theme } from "../utils/theme.ts"
21
4
22
5
export function ThemeSwitcher() {
23
6
const [theme, setTheme] = createSignal<Theme>(getInitialTheme())
+3
src/routes/__root.tsx
reviewed
···
5
5
import "./main.css"
6
6
import "./root.css"
7
7
import { useMe } from "../utils/auth.ts"
8
8
+
import { useTheme } from "../utils/theme.ts"
8
9
9
10
export const Route = createRootRoute({
10
11
component: RootComponent,
···
12
13
13
14
function RootComponent() {
14
15
const query = useMe()
16
16
+
17
17
+
useTheme()
15
18
16
19
return (
17
20
<main>
+21
src/utils/theme.ts
reviewed
···
1
1
+
export type Theme = "light" | "dark"
2
2
+
3
3
+
export const STORAGE_KEY = "theme"
4
4
+
5
5
+
function getSystemTheme(): Theme {
6
6
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
7
7
+
? "dark"
8
8
+
: "light"
9
9
+
}
10
10
+
11
11
+
export function getInitialTheme(): Theme {
12
12
+
const stored = localStorage.getItem(STORAGE_KEY)
13
13
+
if (stored === "light" || stored === "dark") {
14
14
+
return stored
15
15
+
}
16
16
+
return getSystemTheme()
17
17
+
}
18
18
+
19
19
+
export function useTheme() {
20
20
+
document.documentElement.dataset.theme = getInitialTheme()
21
21
+
}