import { get, type Writable, writable } from "svelte/store"; import { GetPaymentsForMonth } from "$wails/main/App"; import { main } from "$wails/models"; import { toast } from "svelte-sonner"; import { scrollingTimeFrameStore } from "$lib/store/scrollingTimeFrameStore"; async function createStore(): Promise> { const payments: main.Payment[] = []; const res = await GetPaymentsForMonth(get(scrollingTimeFrameStore).from); if (!res.success) { toast.error("Error getting payments " + res.error); } else { payments.push(...res.data); } const { subscribe, update, set } = writable(payments); return { subscribe, update, set, }; } const lastMonthPaymentsStore = await createStore(); scrollingTimeFrameStore.subscribe(async (timeframe) => { const res = await GetPaymentsForMonth(timeframe.from); if (!res.success) { toast.error("Error getting payments " + res.error); return; } lastMonthPaymentsStore.set(res.data); }); export { lastMonthPaymentsStore };