From 17b9937c6ab82defc0b23cda3ccf52687e5b98d8 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Mon, 10 Jun 2024 18:58:08 +0200 Subject: [PATCH 01/11] Added category input component --- components/calendar/Calendar.vue | 21 +++++- components/calendar/form/CreateEvent.vue | 14 +++- components/calendar/form/UpdateEvent.vue | 14 +++- components/calendar/input/EventCategories.vue | 72 +++++++++++++++++++ components/ui/checkbox/Checkbox.vue | 33 +++++++++ components/ui/checkbox/index.ts | 1 + models/CalendarEvent.ts | 5 +- server/api/calendars/categories/query.get.ts | 15 ++++ server/api/calendars/events/[id].patch.ts | 2 +- server/api/calendars/events/create.post.ts | 1 + stores/EventStore.ts | 11 ++- 11 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 components/calendar/input/EventCategories.vue create mode 100644 components/ui/checkbox/Checkbox.vue create mode 100644 components/ui/checkbox/index.ts create mode 100644 server/api/calendars/categories/query.get.ts diff --git a/components/calendar/Calendar.vue b/components/calendar/Calendar.vue index 9506e05..cf5c9b8 100644 --- a/components/calendar/Calendar.vue +++ b/components/calendar/Calendar.vue @@ -12,11 +12,12 @@ const route = useRoute() const worldId = route.params.id const { setCalendarId, setMonths, setDefaultDate, currentConfig, selectedDate, jumpToDate } = useCalendar() -const { setEvents } = useCalendarEvents() +const { setEvents, setCategories } = useCalendarEvents() const { setCharacters } = useCharacters() const { data: calendar, pending: calPending, refresh: calRefresh } = await useLazyFetch(`/api/calendars/query?world_id=${worldId}`) const { data: characters, pending: charPending, refresh: charRefresh } = await useLazyFetch(`/api/characters/query?world_id=${worldId}`) +const { data: categories, pending: categoryPending, refresh: categoryRefresh } = await useLazyFetch(`/api/calendars/categories/query`) if (!calendar.value) { await calRefresh() @@ -37,6 +38,15 @@ if (!calendar.value) { setEvents(calendar.value?.data?.events) } } + +if (!categories.value) { + await categoryRefresh() +} else { + if (categories.value?.data) { + setCategories(categories.value?.data) + } +} + if (!characters.value) { await charRefresh() } else { @@ -61,6 +71,13 @@ watch(calPending, (newStatus) => { } } }) +watch(categoryPending, (newStatus) => { + if (!newStatus) { + if (categories.value?.data) { + setCategories(categories.value?.data) + } + } +}) watch(charPending, (newStatus) => { if (!newStatus) { if (characters.value?.data) { @@ -103,7 +120,7 @@ onMounted(() => {