fix: color schemes not saving/updating

This commit is contained in:
James Xylight committed 2025-02-12 16:48:35 -08:00
1 parent 80df5c5409
commit e9adaf991b
2 files changed
+16 -22

No files matched your search

+1 -8
View File
@@ -40,6 +40,7 @@
import { t } from '$lib/translations'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { env } from '$env/dynamic/public'
let showInstance = $state(false)
@@ -217,14 +218,6 @@
>
<Icon src={ServerStack} size="16" micro />
</Button>
<Button
color="tertiary"
href="https://buymeacoffee.com/xylight"
title={$t('nav.menu.donate')}
size="square-md"
>
<Icon src={Heart} size="16" micro />
</Button>
<Button
color="tertiary"
href="https://github.com/Xyphyn/Photon"
+15 -14
View File
@@ -90,6 +90,21 @@ $effect.root(() => {
)
}
})
$effect(() => {
if (browser) {
const prefersDark = window.matchMedia(
'(prefers-color-scheme: dark)',
).matches
const html = document.querySelector('html')
if (theme.colorScheme == 'system')
html?.classList.toggle('dark', prefersDark)
else html?.classList.toggle('dark', theme.colorScheme === 'dark')
localStorage.setItem('colorScheme', theme.colorScheme)
}
})
})
const configuredColorScheme = env.PUBLIC_COLORSCHEME ?? 'system'
@@ -101,20 +116,6 @@ class ThemeState {
configuredColorScheme
this.#colorScheme = localColorScheme
if (browser) {
const prefersDark = window.matchMedia(
'(prefers-color-scheme: dark)',
).matches
const html = document.querySelector('html')
if (this.#colorScheme == 'system')
html?.classList.toggle('dark', prefersDark)
else html?.classList.toggle('dark', this.#colorScheme === 'dark')
localStorage.setItem('colorScheme', this.#colorScheme)
}
}
#data = $state<ThemeData>(