generated from dave/wails-template
33 lines
942 B
TypeScript
33 lines
942 B
TypeScript
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();
|
|
thism.setMonth(thism.getMonth() - 1);
|
|
lastm.setMonth(lastm.getMonth() - 2);
|
|
|
|
const { subscribe, update, set } = writable({ from: lastm, to: thism });
|
|
return {
|
|
subscribe,
|
|
update,
|
|
set,
|
|
next: () => {
|
|
update((frame: ScrollingTimeframe) => {
|
|
frame.from.setMonth(frame.from.getMonth() + 1);
|
|
frame.to.setMonth(frame.to.getMonth() + 1);
|
|
return frame;
|
|
});
|
|
},
|
|
prev: () => {
|
|
update((frame: ScrollingTimeframe) => {
|
|
frame.from.setMonth(frame.from.getMonth() - 1);
|
|
frame.to.setMonth(frame.to.getMonth() - 1);
|
|
return frame;
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
export const scrollingTimeFrameStore = await createStore();
|