fix: test failing, theme toggle was put in wrong file
This commit is contained in:
1 parent
e08434805d
commit
88f09e2b7d
3 files changed
+42
-42
No files matched your search
@@ -11,44 +11,3 @@ export const isVideo = (inputUrl: string | undefined) => {
|
||||
|
||||
return url.endsWith('mp4') || url.endsWith('webm') || url.endsWith('mov')
|
||||
}
|
||||
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
export const theme = writable<'system' | 'light' | 'dark'>('system')
|
||||
|
||||
export const toggleTheme = () => {
|
||||
theme.update((theme) => {
|
||||
if (theme == 'light') {
|
||||
return 'dark'
|
||||
} else if (theme == 'dark') {
|
||||
return 'system'
|
||||
} else {
|
||||
return 'light'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof localStorage != 'undefined') {
|
||||
const localTheme: 'system' | 'light' | 'dark' =
|
||||
(localStorage.getItem('theme') as 'system' | 'light' | 'dark') || 'system'
|
||||
|
||||
theme.update((theme) => localTheme)
|
||||
|
||||
theme.subscribe((theme) => {
|
||||
if (typeof document != 'undefined') {
|
||||
const prefersDark = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)'
|
||||
).matches
|
||||
|
||||
const html = document.querySelector('html')
|
||||
|
||||
if (theme == 'system') {
|
||||
html?.classList.toggle('dark', prefersDark)
|
||||
} else {
|
||||
html?.classList.toggle('dark', theme === 'dark')
|
||||
}
|
||||
|
||||
localStorage.setItem('theme', theme)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user