Cleanup, progress storing and settings handling
This commit is contained in:
25
src/lib/settings/progress.ts
Normal file
25
src/lib/settings/progress.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { browser } from "$app/environment";
|
||||
import { writable } from "svelte/store";
|
||||
|
||||
type Progress = Record<string, number> | undefined
|
||||
|
||||
const stored = browser ? window.localStorage.getItem('progress') : undefined
|
||||
const initial: Progress = stored && browser ? JSON.parse(stored) : undefined
|
||||
|
||||
export const progress = writable<Progress>(initial);
|
||||
|
||||
export function updateProgress(volume: string, value: number) {
|
||||
progress.update((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
[volume]: value
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
progress.subscribe((progress) => {
|
||||
if (browser) {
|
||||
window.localStorage.setItem('progress', JSON.stringify(progress))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user