generated from dave/wails-template
Rework "nowStore" to scrollingTimeFrameStore that contains both from and to dates
This commit is contained in:
31
frontend/src/lib/store/scrollingTimeFrameStore.ts
Normal file
31
frontend/src/lib/store/scrollingTimeFrameStore.ts
Normal 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();
|
||||
Reference in New Issue
Block a user