From 7219ede40b597b9430c71a01f5fb865d7117d6e2 Mon Sep 17 00:00:00 2001 From: Steven Bontenbal Date: Sat, 27 Jan 2024 18:00:52 +0100 Subject: [PATCH] Fix type errors on song overview --- frontend/src/components/Song.vue | 1 + frontend/src/stores/categoryStore.ts | 20 +++++++------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/Song.vue b/frontend/src/components/Song.vue index c1c7bae..4785530 100644 --- a/frontend/src/components/Song.vue +++ b/frontend/src/components/Song.vue @@ -359,6 +359,7 @@ const remove = () => const edit = () => { draftValues.value = song.value as DraftSong; + draftValues.value.songbook ??= {} draftSongCategories.value = Object.assign({}, songCategories.value); editing.value = true; } diff --git a/frontend/src/stores/categoryStore.ts b/frontend/src/stores/categoryStore.ts index 19d01d2..09183a3 100644 --- a/frontend/src/stores/categoryStore.ts +++ b/frontend/src/stores/categoryStore.ts @@ -13,24 +13,18 @@ export type CategoriesState = { export const useCategories = defineStore('categories', { state: () => ({ categories: {}, - categoriesBySongId: new Map(), + categoriesBySongId: new CacheListMap(), loading: false } as CategoriesState), getters: {}, actions: { async fetchAll() { this.loading = true; - api.getAllCategories() - .then(response => { - this.categories = { - season: response.data.filter(category => category.type === "SEASON"), - liturgical: response.data.filter(category => category.type === "LITURGICAL_MOMENT") - } - }) - .catch((error) => { - console.log(error); - this.error = "Failed to load categories"; - }); + const response = await api.getAllCategories() + this.categories = { + season: response.data.filter(category => category.type === "SEASON"), + liturgical: response.data.filter(category => category.type === "LITURGICAL_MOMENT") + } this.loading = false; }, @@ -52,7 +46,7 @@ export const useCategories = defineStore('categories', { let newCategories = categories.filter(draftCategory => !previousCategories.some(previousCategory => draftCategory.id === previousCategory.id)); let deletedCategories = previousCategories.filter(previousCategory => !categories.some(draftCategory => previousCategory.id === draftCategory.id)); const promises = []; - if(newCategories.length) { + if (newCategories.length) { const posted = api.postSongCategories(songId, newCategories.map(songCategory => songCategory._links.self.href)); promises.push(posted); }