From 57930d0e5d0f7897724826fe6610a1c5b30626aa Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 15 Feb 2022 08:25:41 +0000 Subject: [PATCH] Rewrite addCategoriesForMonth with patch call --- web/src/stores/budget-account.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index b8f36da..a56f0fc 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -104,16 +104,17 @@ export const useAccountStore = defineStore("budget/account", { const response = await result.json(); this.addCategoriesForMonth(year, month, response.Categories); }, - addCategoriesForMonth(year : number, month : number, categories : Category[]) : void { - const yearMap = this.Months.get(year) || new Map>(); - this.Months.set(year, yearMap); + addCategoriesForMonth(year: number, month: number, categories: Category[]): void { + this.$patch((state) => { + const yearMap = state.Months.get(year) || new Map>(); + const monthMap = yearMap.get(month) || new Map(); + for (const category of categories) { + monthMap.set(category.ID, category); + } - const monthMap = yearMap.get(month) || new Map(); - yearMap.set(month, monthMap); - - for (const category of categories){ - monthMap.set(category.ID, category); - } + yearMap.set(month, monthMap); + state.Months.set(year, yearMap); + }); }, logout() { this.$reset()