diff options
| author | Fuwn <[email protected]> | 2023-09-03 18:25:03 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-03 18:25:03 -0700 |
| commit | ddc18557b5de23fee2e0723b305fd8d8de62bd17 (patch) | |
| tree | 1d637c453ee627f62f2cdc63c3bb20d11f3b6b5d /src/stores | |
| parent | refactor(settings): remove useless triple equal (diff) | |
| download | due.moe-ddc18557b5de23fee2e0723b305fd8d8de62bd17.tar.xz due.moe-ddc18557b5de23fee2e0723b305fd8d8de62bd17.zip | |
feat(settings): move cache minutes to settings
Diffstat (limited to 'src/stores')
| -rw-r--r-- | src/stores/cacheMangaMinutes.ts | 14 | ||||
| -rw-r--r-- | src/stores/cacheMinutes.ts | 14 | ||||
| -rw-r--r-- | src/stores/settings.ts | 30 |
3 files changed, 17 insertions, 41 deletions
diff --git a/src/stores/cacheMangaMinutes.ts b/src/stores/cacheMangaMinutes.ts deleted file mode 100644 index 6da460b2..00000000 --- a/src/stores/cacheMangaMinutes.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { browser } from '$app/environment'; -import { writable } from 'svelte/store'; - -const cacheMangaMinutes = writable<string>( - browser ? localStorage.getItem('cacheMangaMinutes') ?? '60' : '60' -); - -cacheMangaMinutes.subscribe((value) => { - if (browser) { - localStorage.setItem('cacheMangaMinutes', value); - } -}); - -export default cacheMangaMinutes; diff --git a/src/stores/cacheMinutes.ts b/src/stores/cacheMinutes.ts deleted file mode 100644 index ccea5db1..00000000 --- a/src/stores/cacheMinutes.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { browser } from '$app/environment'; -import { writable } from 'svelte/store'; - -const cacheMinutes = writable<string>( - browser ? localStorage.getItem('cacheMinutes') ?? '30' : '30' -); - -cacheMinutes.subscribe((value) => { - if (browser) { - localStorage.setItem('cacheMinutes', value); - } -}); - -export default cacheMinutes; 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 })) }; }; |