From 79b89a01e5b705f178ec6ab8a6caa19b0e134065 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 19 Aug 2024 13:09:14 +0200 Subject: [PATCH] Refresh payment stores on time frame change --- frontend/src/lib/store/lastMonthPaymentsStore.ts | 12 +++++++++++- frontend/src/lib/store/thisMonthPaymentsStore.ts | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/store/lastMonthPaymentsStore.ts b/frontend/src/lib/store/lastMonthPaymentsStore.ts index 939952f..b7d3836 100644 --- a/frontend/src/lib/store/lastMonthPaymentsStore.ts +++ b/frontend/src/lib/store/lastMonthPaymentsStore.ts @@ -21,4 +21,14 @@ async function createStore(): Promise> { }; } -export const lastMonthPaymentsStore = await createStore(); +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 }; diff --git a/frontend/src/lib/store/thisMonthPaymentsStore.ts b/frontend/src/lib/store/thisMonthPaymentsStore.ts index ecf9f2b..7caebb0 100644 --- a/frontend/src/lib/store/thisMonthPaymentsStore.ts +++ b/frontend/src/lib/store/thisMonthPaymentsStore.ts @@ -21,4 +21,14 @@ async function createStore(): Promise> { }; } -export const thisMonthPaymentsStore = await createStore(); +const thisMonthPaymentsStore = await createStore(); +scrollingTimeFrameStore.subscribe(async (timeframe) => { + const res = await GetPaymentsForMonth(timeframe.to); + if (!res.success) { + toast.error("Error getting payments " + res.error); + return; + } + thisMonthPaymentsStore.set(res.data); +}); + +export { thisMonthPaymentsStore };