diff options
Diffstat (limited to 'src/stores/settings.ts')
| -rw-r--r-- | src/stores/settings.ts | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/stores/settings.ts b/src/stores/settings.ts index 30f1c34d..9396ec74 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -2,8 +2,8 @@ import { browser } from '$app/environment'; import { writable } from 'svelte/store'; interface Settings { - // cacheMangaMinutes: number; - // cacheMinutes: number; + cacheMangaMinutes: number; + cacheMinutes: number; closeAnimeByDefault: boolean; closeMangaByDefault: boolean; displayNotStarted: boolean; @@ -13,8 +13,8 @@ interface Settings { } const defaultSettings: Settings = { - // cacheMangaMinutes: 60, - // cacheMinutes: 30, + cacheMangaMinutes: 60, + cacheMinutes: 30, closeAnimeByDefault: false, closeMangaByDefault: false, displayNotStarted: false, @@ -24,7 +24,16 @@ const defaultSettings: Settings = { }; const createStore = () => { - const { subscribe, set, update } = writable<Settings>(defaultSettings); + const { subscribe, set, update } = writable<Settings>( + JSON.parse( + browser + ? localStorage.getItem('settings') ?? JSON.stringify(defaultSettings) + : JSON.stringify(defaultSettings) + ) + ); + let state: Settings; + + subscribe((value) => (state = value)); return { subscribe, @@ -32,13 +41,8 @@ const createStore = () => { update, reset: () => set(defaultSettings), get: () => { - const settings = JSON.parse( - browser - ? localStorage.getItem('settings') ?? JSON.stringify(defaultSettings) - : JSON.stringify(defaultSettings) - ); const keys = Object.keys(defaultSettings); - const settingsKeys = Object.keys(settings); + const settingsKeys = Object.keys(state); if (keys.length !== settingsKeys.length) { return defaultSettings; @@ -50,9 +54,9 @@ const createStore = () => { } } - return settings; + return state; }, - setKey: (key: keyof Settings, value: any) => + setKey: (key: keyof Settings, value: unknown) => update((settings) => ({ ...settings, [key]: value })) }; }; |