Fixed theme selector incorrectly showing dark mode on first visit

This commit is contained in:
2025-02-13 10:48:29 +11:00
parent 2d52084fa7
commit 5b1532b86d

View File

@@ -11,7 +11,7 @@ templ Global() {
lang="en" lang="en"
x-data="{ x-data="{
theme: localStorage.getItem('theme') theme: localStorage.getItem('theme')
|| localStorage.setItem('theme', 'system')}" || 'system'}"
x-init="$watch('theme', (val) => localStorage.setItem('theme', val))" x-init="$watch('theme', (val) => localStorage.setItem('theme', val))"
x-bind:class="{'dark': theme === 'dark' || (theme === 'system' && x-bind:class="{'dark': theme === 'dark' || (theme === 'system' &&
window.matchMedia('(prefers-color-scheme: dark)').matches)}" window.matchMedia('(prefers-color-scheme: dark)').matches)}"