From 6749fdb46ea5edb104c5cbd89beaa3072ae642a7 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Wed, 5 Jun 2024 18:28:38 +0200 Subject: [PATCH 1/7] Moved event modal states and functions to event store --- components/calendar/Calendar.vue | 4 +- components/calendar/CalendarEventDetails.vue | 4 +- components/calendar/form/DeleteEvent.vue | 112 +++++++++++++++++++ stores/CalendarStore.ts | 11 -- stores/EventStore.ts | 36 +++++- 5 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 components/calendar/form/DeleteEvent.vue diff --git a/components/calendar/Calendar.vue b/components/calendar/Calendar.vue index b16f81e..063aa40 100644 --- a/components/calendar/Calendar.vue +++ b/components/calendar/Calendar.vue @@ -7,7 +7,8 @@ import CenturyLayout from './state/centennially/Layout.vue' import DecadeLayout from './state/decennially/Layout.vue' import YearLayout from './state/yearly/Layout.vue' -const { isAdvancedSearchOpen, isEditEventModalOpen } = storeToRefs(useCalendar()) +const { isAdvancedSearchOpen } = storeToRefs(useCalendar()) +const { isEditEventModalOpen, isDeleteEventModalOpen } = storeToRefs(useCalendarEvents()) const route = useRoute() const worldId = route.params.id @@ -111,5 +112,6 @@ onMounted(() => { + diff --git a/components/calendar/CalendarEventDetails.vue b/components/calendar/CalendarEventDetails.vue index 9816ace..b7c252a 100644 --- a/components/calendar/CalendarEventDetails.vue +++ b/components/calendar/CalendarEventDetails.vue @@ -11,8 +11,8 @@ import { PhDotsThreeOutlineVertical } from '@phosphor-icons/vue' -const { defaultDate, getFormattedDateTitle, jumpToDate, revealEditEventModal, getRelativeString } = useCalendar() -const { deleteEvent } = useCalendarEvents() +const { defaultDate, getFormattedDateTitle, jumpToDate, getRelativeString } = useCalendar() +const { deleteEvent, revealEditEventModal } = useCalendarEvents() const { lastActiveEvent } = storeToRefs(useCalendarEvents()) const props = defineProps<{ diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue new file mode 100644 index 0000000..58c4c8a --- /dev/null +++ b/components/calendar/form/DeleteEvent.vue @@ -0,0 +1,112 @@ + + + + + + + Modifier l'évènement + + + Mettre à jour les données de l'évènement + + + + + + + + + + + + + + + + + + + + — + + + + + + + + {{ formErrors.message }} + + + + + + Sauvegarder + + + + + + + diff --git a/stores/CalendarStore.ts b/stores/CalendarStore.ts index 1b7fe75..2d9fd4f 100644 --- a/stores/CalendarStore.ts +++ b/stores/CalendarStore.ts @@ -298,15 +298,6 @@ export const useCalendar = defineStore('calendar', () => { isAdvancedSearchOpen.value = true } - /** - * State for advanced search modal - */ - const isEditEventModalOpen: Ref = ref(false) - - function revealEditEventModal() { - isEditEventModalOpen.value = true - } - /** * Switches the active viewType * @@ -649,8 +640,6 @@ export const useCalendar = defineStore('calendar', () => { isCurrentScreenActive, isAdvancedSearchOpen, revealAdvancedSearch, - isEditEventModalOpen, - revealEditEventModal, convertDateToDays, getDifferenceInDays, areDatesIdentical, diff --git a/stores/EventStore.ts b/stores/EventStore.ts index d703b5a..6281662 100644 --- a/stores/EventStore.ts +++ b/stores/EventStore.ts @@ -165,6 +165,24 @@ export const useCalendarEvents = defineStore('calendar-events', () => { } } + /** + * State for event modal edition + */ + const isEditEventModalOpen: Ref = ref(false) + + function revealEditEventModal() { + isEditEventModalOpen.value = true + } + + /** + * State for event modal edition + */ + const isDeleteEventModalOpen: Ref = ref(false) + + function revealDeleteEventModal() { + isDeleteEventModalOpen.value = true + } + /** * EVENT CREATION FUNCTIONS */ @@ -219,5 +237,21 @@ export const useCalendarEvents = defineStore('calendar-events', () => { } } - return { allEvents, setEvents, currentEvents, getRelativeEventFromDate, getRelativeEventFromEvent, eventSkeleton, resetSkeleton, submitSkeleton, lastActiveEvent, updateEventFromSkeleton, deleteEvent } + return { + allEvents, + setEvents, + currentEvents, + getRelativeEventFromDate, + getRelativeEventFromEvent, + eventSkeleton, + resetSkeleton, + submitSkeleton, + lastActiveEvent, + updateEventFromSkeleton, + deleteEvent, + isEditEventModalOpen, + revealEditEventModal, + isDeleteEventModalOpen, + revealDeleteEventModal + } }) From 53024c6117076631ac509b64a1501621c873eb6c Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Wed, 5 Jun 2024 18:35:13 +0200 Subject: [PATCH 2/7] Added delete modal confirmation --- components/calendar/CalendarEventDetails.vue | 13 +++- components/calendar/form/DeleteEvent.vue | 63 +++----------------- stores/EventStore.ts | 12 ++-- 3 files changed, 23 insertions(+), 65 deletions(-) diff --git a/components/calendar/CalendarEventDetails.vue b/components/calendar/CalendarEventDetails.vue index b7c252a..e588198 100644 --- a/components/calendar/CalendarEventDetails.vue +++ b/components/calendar/CalendarEventDetails.vue @@ -12,7 +12,7 @@ import { } from '@phosphor-icons/vue' const { defaultDate, getFormattedDateTitle, jumpToDate, getRelativeString } = useCalendar() -const { deleteEvent, revealEditEventModal } = useCalendarEvents() +const { revealEditEventModal, revealDeleteEventModal } = useCalendarEvents() const { lastActiveEvent } = storeToRefs(useCalendarEvents()) const props = defineProps<{ @@ -47,6 +47,15 @@ function deployEditModal() { revealEditEventModal() commandMenuOpened.value = false } + +/** + * Confirm event deletion + */ +function deployDeleteModal() { + lastActiveEvent.value = { ...props.event } + revealDeleteEventModal() + commandMenuOpened.value = false +} @@ -146,7 +155,7 @@ function deployEditModal() { Modifier - Supprimer + Supprimer diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue index 58c4c8a..822e344 100644 --- a/components/calendar/form/DeleteEvent.vue +++ b/components/calendar/form/DeleteEvent.vue @@ -1,9 +1,6 @@ + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogAction.vue b/components/ui/alert-dialog/AlertDialogAction.vue new file mode 100644 index 0000000..d3414bf --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogAction.vue @@ -0,0 +1,20 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogCancel.vue b/components/ui/alert-dialog/AlertDialogCancel.vue new file mode 100644 index 0000000..08302c0 --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogCancel.vue @@ -0,0 +1,20 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogContent.vue b/components/ui/alert-dialog/AlertDialogContent.vue new file mode 100644 index 0000000..9f09909 --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogContent.vue @@ -0,0 +1,42 @@ + + + + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogDescription.vue b/components/ui/alert-dialog/AlertDialogDescription.vue new file mode 100644 index 0000000..9682cbb --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogDescription.vue @@ -0,0 +1,25 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogFooter.vue b/components/ui/alert-dialog/AlertDialogFooter.vue new file mode 100644 index 0000000..55d0a0e --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogFooter.vue @@ -0,0 +1,21 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogHeader.vue b/components/ui/alert-dialog/AlertDialogHeader.vue new file mode 100644 index 0000000..c61c449 --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogHeader.vue @@ -0,0 +1,16 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogTitle.vue b/components/ui/alert-dialog/AlertDialogTitle.vue new file mode 100644 index 0000000..50c583d --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogTitle.vue @@ -0,0 +1,22 @@ + + + + + + + diff --git a/components/ui/alert-dialog/AlertDialogTrigger.vue b/components/ui/alert-dialog/AlertDialogTrigger.vue new file mode 100644 index 0000000..4f5e2fd --- /dev/null +++ b/components/ui/alert-dialog/AlertDialogTrigger.vue @@ -0,0 +1,11 @@ + + + + + + + diff --git a/components/ui/alert-dialog/index.ts b/components/ui/alert-dialog/index.ts new file mode 100644 index 0000000..91d138a --- /dev/null +++ b/components/ui/alert-dialog/index.ts @@ -0,0 +1,9 @@ +export { default as AlertDialog } from './AlertDialog.vue' +export { default as AlertDialogTrigger } from './AlertDialogTrigger.vue' +export { default as AlertDialogContent } from './AlertDialogContent.vue' +export { default as AlertDialogHeader } from './AlertDialogHeader.vue' +export { default as AlertDialogTitle } from './AlertDialogTitle.vue' +export { default as AlertDialogDescription } from './AlertDialogDescription.vue' +export { default as AlertDialogFooter } from './AlertDialogFooter.vue' +export { default as AlertDialogAction } from './AlertDialogAction.vue' +export { default as AlertDialogCancel } from './AlertDialogCancel.vue' From edeaaa1e1911441fb68b6e7b60e1aa2b111a20a9 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Wed, 5 Jun 2024 21:39:47 +0200 Subject: [PATCH 4/7] Removed redundant data pass --- components/calendar/Calendar.vue | 9 +++---- components/calendar/form/DeleteEvent.vue | 23 ++++++++-------- components/calendar/form/UpdateEvent.vue | 26 +++++++++++-------- components/calendar/search/CalendarSearch.vue | 11 ++++---- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/components/calendar/Calendar.vue b/components/calendar/Calendar.vue index 063aa40..202e877 100644 --- a/components/calendar/Calendar.vue +++ b/components/calendar/Calendar.vue @@ -7,9 +7,6 @@ import CenturyLayout from './state/centennially/Layout.vue' import DecadeLayout from './state/decennially/Layout.vue' import YearLayout from './state/yearly/Layout.vue' -const { isAdvancedSearchOpen } = storeToRefs(useCalendar()) -const { isEditEventModalOpen, isDeleteEventModalOpen } = storeToRefs(useCalendarEvents()) - const route = useRoute() const worldId = route.params.id @@ -110,8 +107,8 @@ onMounted(() => { - - - + + + diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue index 822e344..3fcfcdd 100644 --- a/components/calendar/form/DeleteEvent.vue +++ b/components/calendar/form/DeleteEvent.vue @@ -1,5 +1,6 @@ - - + - Supprimer l'évènement + Supprimer l'évènement - + Les données associés à cet évènement seront supprimées et vous ne pourrez plus les récupérer ! - + @@ -60,6 +61,6 @@ async function handleSubmit() { - - + + diff --git a/components/calendar/form/UpdateEvent.vue b/components/calendar/form/UpdateEvent.vue index 58c4c8a..0bf23da 100644 --- a/components/calendar/form/UpdateEvent.vue +++ b/components/calendar/form/UpdateEvent.vue @@ -2,7 +2,8 @@ import { PhAlarm } from '@phosphor-icons/vue' import { VisuallyHidden } from 'radix-vue' -const isModalOpened = defineModel({ default: false }) +const { isEditEventModalOpen } = storeToRefs(useCalendarEvents()) + const { resetSkeleton, updateEventFromSkeleton } = useCalendarEvents() const { eventSkeleton, lastActiveEvent } = storeToRefs(useCalendarEvents()) @@ -11,7 +12,7 @@ const formErrors = reactive<{ message: string | null }>({ }) // Watch the popover state -watch(isModalOpened, (hasOpened, _o) => { +watch(isEditEventModalOpen, (hasOpened, _o) => { if (hasOpened && lastActiveEvent.value) { eventSkeleton.value = { ...lastActiveEvent.value } } else { @@ -23,7 +24,7 @@ async function handleSubmit() { try { await updateEventFromSkeleton() - isModalOpened.value = false + isEditEventModalOpen.value = false } catch (err) { if (err instanceof Error) { formErrors.message = err.message @@ -33,8 +34,8 @@ async function handleSubmit() { - - + - Modifier l'évènement + Modifier l'évènement - + Mettre à jour les données de l'évènement - + @@ -100,13 +101,16 @@ async function handleSubmit() { - + + + Annuler + Sauvegarder - - + + diff --git a/components/calendar/search/CalendarSearch.vue b/components/calendar/search/CalendarSearch.vue index 2b2a457..74dba7b 100644 --- a/components/calendar/search/CalendarSearch.vue +++ b/components/calendar/search/CalendarSearch.vue @@ -27,10 +27,9 @@ import { import SearchList from './lists/SearchList.vue' import type { Category } from '~/models/Category' -const { characters } = storeToRefs(useCharacters()) +const { isAdvancedSearchOpen } = storeToRefs(useCalendar()) const { allEvents } = storeToRefs(useCalendarEvents()) - -const modalOpen = defineModel({ default: false }) +const { characters } = storeToRefs(useCharacters()) const searchQuery = ref('') // const searchEnough = computed(() => searchQuery.value.length >= 2) @@ -170,14 +169,14 @@ function resetSearch() { * Opens the search Uidialog */ function openUiDialog() { - modalOpen.value = true + isAdvancedSearchOpen.value = true } /** * Closes the search Uidialog */ function closeUiDialog() { - modalOpen.value = false + isAdvancedSearchOpen.value = false } /** @@ -233,7 +232,7 @@ function handleCategorySelect(e: (Category)) { - + + {{ formErrors.message }} - - - - Supprimer - - + + + + Annuler + + + Supprimer + + diff --git a/components/calendar/form/UpdateEvent.vue b/components/calendar/form/UpdateEvent.vue index 0bf23da..03f3f7d 100644 --- a/components/calendar/form/UpdateEvent.vue +++ b/components/calendar/form/UpdateEvent.vue @@ -20,7 +20,7 @@ watch(isEditEventModalOpen, (hasOpened, _o) => { } }) -async function handleSubmit() { +async function handleAction() { try { await updateEventFromSkeleton() @@ -51,7 +51,7 @@ async function handleSubmit() { - + - - - - Annuler - - - Sauvegarder - - + + + Annuler + + + Sauvegarder + + From 4972c2638535722b2b1e470e0002d6d833ffd68b Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Wed, 5 Jun 2024 23:21:33 +0200 Subject: [PATCH 6/7] Removed resetSkeleton call Same logic from commit b71f7745a41725c92920a230351854fe17a44a4b, as this would remove useful data from the skeleton used to splice / change the client side data --- components/calendar/form/DeleteEvent.vue | 4 ++-- components/calendar/form/UpdateEvent.vue | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue index 0892603..97a2f59 100644 --- a/components/calendar/form/DeleteEvent.vue +++ b/components/calendar/form/DeleteEvent.vue @@ -12,8 +12,6 @@ const formErrors = reactive<{ message: string | null }>({ watch(isDeleteEventModalOpen, (hasOpened, _o) => { if (hasOpened && lastActiveEvent.value) { eventSkeleton.value = { ...lastActiveEvent.value } - } else { - resetSkeleton() } }) @@ -26,6 +24,8 @@ async function handleAction() { if (err instanceof Error) { formErrors.message = err.message } + } finally { + resetSkeleton() } } diff --git a/components/calendar/form/UpdateEvent.vue b/components/calendar/form/UpdateEvent.vue index 03f3f7d..08d5d28 100644 --- a/components/calendar/form/UpdateEvent.vue +++ b/components/calendar/form/UpdateEvent.vue @@ -15,8 +15,6 @@ const formErrors = reactive<{ message: string | null }>({ watch(isEditEventModalOpen, (hasOpened, _o) => { if (hasOpened && lastActiveEvent.value) { eventSkeleton.value = { ...lastActiveEvent.value } - } else { - resetSkeleton() } }) @@ -29,6 +27,8 @@ async function handleAction() { if (err instanceof Error) { formErrors.message = err.message } + } finally { + resetSkeleton() } } From 85e67105600090d9d67ecb1fe760cb3e7793ccf0 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Wed, 5 Jun 2024 23:24:37 +0200 Subject: [PATCH 7/7] Removed useless prop from alert dialog --- components/calendar/form/DeleteEvent.vue | 2 +- components/calendar/form/UpdateEvent.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue index 97a2f59..224d563 100644 --- a/components/calendar/form/DeleteEvent.vue +++ b/components/calendar/form/DeleteEvent.vue @@ -31,7 +31,7 @@ async function handleAction() { - + - +