diff --git a/src/lib/stores/dateStore.ts b/src/lib/stores/dateStore.ts new file mode 100644 index 0000000..97c723b --- /dev/null +++ b/src/lib/stores/dateStore.ts @@ -0,0 +1,18 @@ +import { writable } from 'svelte/store'; + +function createDateStore() { + const storedDate = typeof localStorage !== 'undefined' ? localStorage.getItem('selectedDate') : null; + const initialDate = storedDate ? storedDate : new Date().toISOString().split('T')[0]; + + const { subscribe, set } = writable(initialDate); + + return { + subscribe, + set: (newDate: string) => { + localStorage.setItem('selectedDate', newDate); + set(newDate); + } + }; +} + +export const selectedDate = createDateStore();