Rework "nowStore" to scrollingTimeFrameStore that contains both from and to dates

This commit is contained in:
2024-08-19 12:45:37 +02:00
parent c5613ee0cc
commit f018459818
8 changed files with 49 additions and 42 deletions

View File

@@ -0,0 +1,31 @@
import { type ScrollingTimeframe } from "$lib/types";
import { type Writable, writable } from "svelte/store";
async function createStore(): Promise<Writable<ScrollingTimeframe> & { next: Function; prev: Function }> {
const thism = new Date();
const lastm = new Date();
lastm.setMonth(thism.getMonth() - 1);
const { subscribe, update, set } = writable({ from: thism, to: lastm });
return {
subscribe,
update,
set,
next: () => {
update((frame: ScrollingTimeframe) => {
frame.from.setMonth(frame.from.getMonth() + 1);
frame.to.setMonth(frame.from.getMonth() + 1);
return frame;
});
},
prev: () => {
update((frame: ScrollingTimeframe) => {
frame.from.setMonth(frame.from.getMonth() - 1);
frame.to.setMonth(frame.from.getMonth() - 1);
return frame;
});
},
};
}
export const scrollingTimeFrameStore = await createStore();