ux update
This commit is contained in:
parent
6818c469f6
commit
80c7064666
|
|
@ -1,42 +0,0 @@
|
||||||
import { writable } from 'svelte/store';
|
|
||||||
|
|
||||||
export interface AppSettings {
|
|
||||||
showSnoozedTab: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const STORAGE_KEY = 'ka-note-settings';
|
|
||||||
|
|
||||||
const defaults: AppSettings = {
|
|
||||||
showSnoozedTab: true
|
|
||||||
};
|
|
||||||
|
|
||||||
function load(): AppSettings {
|
|
||||||
if (typeof localStorage === 'undefined') return defaults;
|
|
||||||
try {
|
|
||||||
const raw = localStorage.getItem(STORAGE_KEY);
|
|
||||||
return raw ? { ...defaults, ...JSON.parse(raw) } : defaults;
|
|
||||||
} catch {
|
|
||||||
return defaults;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createSettingsStore() {
|
|
||||||
const { subscribe, set, update } = writable<AppSettings>(load());
|
|
||||||
|
|
||||||
subscribe(v => {
|
|
||||||
if (typeof localStorage !== 'undefined') {
|
|
||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(v));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
subscribe,
|
|
||||||
set,
|
|
||||||
update,
|
|
||||||
patch(partial: Partial<AppSettings>) {
|
|
||||||
update(s => ({ ...s, ...partial }));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const settings = createSettingsStore();
|
|
||||||
Loading…
Reference in New Issue