Skip to content

Commit 217121d

Browse files
committed
improve settings handling
1 parent 4f824d0 commit 217121d

File tree

5 files changed

+21
-56
lines changed

5 files changed

+21
-56
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
const defaultTheme = '__DEFAULT_THEME__'
1212

1313
try {
14-
const stored = localStorage.getItem('themeSettings')
14+
const stored = localStorage.getItem('settings')
1515
let themeName = defaultTheme
1616
if (stored) {
1717
const parsed = JSON.parse(stored)

src/App.svelte

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
<script>
22
import '@fontsource-variable/geist-mono'
33
import { settings } from './lib/settings-store.svelte.js'
4+
import { themes } from './lib/themes.js'
45
import Clock from './lib/components/Clock.svelte'
56
import Links from './lib/components/Links.svelte'
67
import Settings from './lib/components/Settings.svelte'
78
import Stats from './lib/components/Stats.svelte'
89
import Todoist from './lib/components/Todoist.svelte'
910
import Weather from './lib/components/Weather.svelte'
11+
import { saveSettings } from './lib/settings-store.svelte.js'
1012
1113
let showSettings = $state(false)
1214
1315
function closeSettings() {
1416
showSettings = false
1517
}
1618
19+
function applyTheme(themeName) {
20+
const theme = themes[themeName] || themes['defaultTheme']
21+
const root = document.documentElement
22+
for (const [key, value] of Object.entries(theme.colors)) {
23+
root.style.setProperty(key, value)
24+
}
25+
}
26+
1727
$effect(() => {
1828
const fontName = settings.font?.trim() || 'Geist Mono Variable'
1929
document.documentElement.style.setProperty(
2030
'--font-family',
2131
`'${fontName}', monospace`
2232
)
2333
})
34+
35+
$effect(() => {
36+
applyTheme(settings.currentTheme)
37+
})
38+
39+
$effect(() => {
40+
saveSettings(settings)
41+
})
2442
</script>
2543
2644
<main>

src/lib/components/Settings.svelte

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script>
22
import { fade, fly } from 'svelte/transition'
33
import { saveSettings, settings } from '../settings-store.svelte.js'
4-
import { getTheme, setTheme } from '../theme-store.svelte.js'
54
import { themeNames, themes } from '../themes.js'
65
import RadioButton from './RadioButton.svelte'
76
@@ -10,12 +9,6 @@
109
// @ts-ignore
1110
const version = __APP_VERSION__
1211
13-
// Reactive theme binding
14-
let currentTheme = $state(getTheme())
15-
$effect(() => {
16-
setTheme(currentTheme)
17-
})
18-
1912
function addLink() {
2013
settings.links = [...settings.links, { title: '', url: '' }]
2114
}
@@ -61,7 +54,7 @@
6154
{#each themeNames as themeName}
6255
<div class="theme-option">
6356
<RadioButton
64-
bind:group={currentTheme}
57+
bind:group={settings.currentTheme}
6558
value={themeName}
6659
>
6760
<div class="theme-preview">

src/lib/settings-store.svelte.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let defaultSettings = {
22
timeFormat: '12hr',
33
font: 'Geist Mono Variable',
4+
currentTheme: 'default',
45
todoistApiToken: '',
56
latitude: null,
67
longitude: null,

src/lib/theme-store.svelte.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)