Rewrite addCategoriesForMonth with patch call
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Jan Bader 2022-02-15 08:25:41 +00:00
parent fe018e1953
commit 57930d0e5d

View File

@ -105,15 +105,16 @@ export const useAccountStore = defineStore("budget/account", {
this.addCategoriesForMonth(year, month, response.Categories);
},
addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
const yearMap = this.Months.get(year) || new Map<number, Map<string, Category>>();
this.Months.set(year, yearMap);
this.$patch((state) => {
const yearMap = state.Months.get(year) || new Map<number, Map<string, Category>>();
const monthMap = yearMap.get(month) || new Map<string, Category>();
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()