Add $lib/stores/dateStore.ts to store date in localStorage
This commit is contained in:
parent
5949160feb
commit
16222089b4
18
src/lib/stores/dateStore.ts
Normal file
18
src/lib/stores/dateStore.ts
Normal file
|
@ -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();
|
Loading…
Reference in New Issue
Block a user