From bb664494f6763b5d5bb1a91a68b228661152f908 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Thu, 7 Apr 2022 08:06:58 +0000 Subject: [PATCH] Use available from API instead of category --- web/src/stores/budget-account.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index 97d6dd3..6fe0d0e 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -9,6 +9,7 @@ interface State { CurrentAccountID: string | null; Categories: Map; Months: Map>>; + Available: Map>; Assignments: []; } @@ -43,6 +44,7 @@ export const useAccountStore = defineStore("budget/account", { Accounts: new Map(), CurrentAccountID: null, Months: new Map>>(), + Available: new Map>(), Categories: new Map(), Assignments: [], }), @@ -96,15 +98,8 @@ export const useAccountStore = defineStore("budget/account", { }, GetIncomeAvailable(state) { return (year: number, month: number) => { - const IncomeCategoryID = this.GetIncomeCategoryID; - if (IncomeCategoryID == null) return 0; - - const categories = this.AllCategoriesForMonth(year, month); - const category = categories.filter( - (x) => x.ID == IncomeCategoryID - )[0]; - if (category == null) return 0; - return category.AvailableLastMonth; + const yearMapAv = this.Available.get(year); + return yearMapAv?.get(month); }; }, CategoryGroupsForMonth(state) { @@ -210,7 +205,7 @@ export const useAccountStore = defineStore("budget/account", { response.Categories.length <= 0 ) return; - this.addCategoriesForMonth(year, month, response.Categories); + this.addCategoriesForMonth(year, month, response.Categories, response.AvailableBalance); }, async EditAccount( accountid: string, @@ -236,7 +231,8 @@ export const useAccountStore = defineStore("budget/account", { addCategoriesForMonth( year: number, month: number, - categories: Category[] + categories: Category[], + available: number ): void { this.$patch((state) => { const yearMap = @@ -250,6 +246,12 @@ export const useAccountStore = defineStore("budget/account", { yearMap.set(month, monthMap); state.Months.set(year, yearMap); + + const yearMapAv = + state.Available.get(year) || + new Map(); + yearMapAv.set(month, available); + state.Available.set(year, yearMapAv); }); }, logout() {