From 02fba36421bc321a188c1c3bc50f3de239150cb2 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sun, 6 Apr 2025 16:08:45 +0200 Subject: [PATCH] Add watch function if categories change --- stores/CalendarStore.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/stores/CalendarStore.ts b/stores/CalendarStore.ts index 57a94fe..3799877 100644 --- a/stores/CalendarStore.ts +++ b/stores/CalendarStore.ts @@ -910,6 +910,28 @@ export const useCalendar = defineStore("calendar", () => { } } + /** + * Updates all events categories + * This is used when the user updates a category and we want to update all events in the client + * @param categories The new categories + * @returns void + */ + function updateAllEventsCategories(categories: Category[]) { + baseEvents.value.forEach((event) => { + if (event.category?.id) { + const category = categories.find((c) => c.id === event.category?.id) + if (category) { + event.category = category + } + } + }) + } + + // Watch for categories changes + watch(categories, (n) => { + updateAllEventsCategories(n) + }) + /** * State for categories modal */