Work on login screen

This commit is contained in:
Jon Staab
2024-08-09 16:22:09 -07:00
parent 51cfa5f0e8
commit 71d819edc7
32 changed files with 698 additions and 534 deletions
+31
View File
@@ -0,0 +1,31 @@
import {throttle} from 'throttle-debounce'
import {browser} from '$app/environment'
import {writable} from 'svelte/store'
export const parseJson = (json: string) => {
if (!json) return null
try {
return JSON.parse(json)
} catch (e) {
return null
}
}
export const getJson = (k: string) =>
browser ? parseJson(localStorage.getItem(k) || "") : null
export const setJson = (k: string, v: any) => {
if (browser) {
localStorage.setItem(k, JSON.stringify(v))
}
}
export const synced = <T>(key: string, defaultValue: T, delay = 300) => {
const init = getJson(key)
const store = writable<T>(init === null ? defaultValue : init)
store.subscribe(throttle(delay, (value: T) => setJson(key, value)))
return store
}