diff options
| author | Fuwn <[email protected]> | 2025-06-12 22:06:31 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-06-12 22:06:31 -0700 |
| commit | e8612618fb20f779ebe2e85edf32d71961d2f1d4 (patch) | |
| tree | fa8565afb8584bbf55f4f4d496c2c350a5a25210 /src/stores/announcementHash.ts | |
| parent | refactor(List): Simplify get-set structure of stateBin usage (diff) | |
| download | due.moe-e8612618fb20f779ebe2e85edf32d71961d2f1d4.tar.xz due.moe-e8612618fb20f779ebe2e85edf32d71961d2f1d4.zip | |
feat: Move remaining localStorage usages to localforage
Diffstat (limited to 'src/stores/announcementHash.ts')
| -rw-r--r-- | src/stores/announcementHash.ts | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/stores/announcementHash.ts b/src/stores/announcementHash.ts index 0ff57b3b..d14c305e 100644 --- a/src/stores/announcementHash.ts +++ b/src/stores/announcementHash.ts @@ -1,12 +1,17 @@ import { browser } from '$app/environment'; import { writable } from 'svelte/store'; +import localforage from 'localforage'; -const announcementHash = writable<number>( - browser ? parseInt(localStorage.getItem('announcementHash') || '1') : 0 -); +const announcementHash = writable<number>(1); -announcementHash.subscribe((value) => { - if (browser) localStorage.setItem('announcementHash', value.toString()); -}); +if (browser) { + localforage.getItem<number>('announcementHash').then((value) => { + if (typeof value === 'number') announcementHash.set(value); + }); + + announcementHash.subscribe((value) => { + localforage.setItem('announcementHash', value); + }); +} export default announcementHash; |