generated from dave/wails-template
Add payment stores
This commit is contained in:
26
frontend/src/lib/store/lastMonthPaymentsStore.ts
Normal file
26
frontend/src/lib/store/lastMonthPaymentsStore.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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 { nowStore } from "$lib/store/nowStore";
|
||||
|
||||
async function createStore(): Promise<Writable<main.Payment[]>> {
|
||||
const payments: main.Payment[] = [];
|
||||
const now = new Date();
|
||||
now.setMonth(get(nowStore).getMonth() - 1)
|
||||
const res = await GetPaymentsForMonth(now);
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
export const lastMonthPaymentsStore = await createStore();
|
||||
Reference in New Issue
Block a user