Merge pull request #22 from AlexisNP/features/add-quick-actions-for-events

Added quick actions for events
This commit is contained in:
AlexisNP
2024-06-09 12:43:30 +02:00
committed by GitHub
4 changed files with 63 additions and 25 deletions

View File

@@ -10,29 +10,54 @@ const props = defineProps<{
}>() }>()
const { areDatesIdentical } = useCalendar() const { areDatesIdentical } = useCalendar()
const { revealEditEventModal, revealDeleteEventModal } = useCalendarEvents()
const { lastActiveEvent } = storeToRefs(useCalendarEvents())
const spansMultipleDays = Boolean(props.event.startDate && props.event.endDate) const spansMultipleDays = Boolean(props.event.startDate && props.event.endDate)
const isStartEvent = spansMultipleDays && areDatesIdentical(props.tileDate, props.event.startDate) const isStartEvent = spansMultipleDays && areDatesIdentical(props.tileDate, props.event.startDate)
const isEndEvent = spansMultipleDays && props.event.endDate && areDatesIdentical(props.tileDate, props.event.endDate) const isEndEvent = spansMultipleDays && props.event.endDate && areDatesIdentical(props.tileDate, props.event.endDate)
const titleCharLimit = 50; const titleCharLimit = 50;
const eventTitle = computed<string>(() => props.event.title.length <= titleCharLimit ? props.event.title : `${props.event.title.slice(0, titleCharLimit)}`) const eventTitle = computed<string>(() => props.event.title.length <= titleCharLimit ? props.event.title : `${props.event.title.slice(0, titleCharLimit)}`)
// Popover code // Popover code
const isPopoverDetailsOpen = ref<boolean>(false) const isPopoverDetailsOpen = ref<boolean>(false)
function handleDoubleClick() {
isPopoverDetailsOpen.value = false
lastActiveEvent.value = { ...props.event }
revealEditEventModal()
}
function handleDelete() {
isPopoverDetailsOpen.value = false
lastActiveEvent.value = { ...props.event }
revealDeleteEventModal()
}
function handleClosePopover() { function handleClosePopover() {
isPopoverDetailsOpen.value = false isPopoverDetailsOpen.value = false
} }
onMounted(() => {
// Listen for keydown events
window.addEventListener('keydown', (e: KeyboardEvent) => {
// If the popover isn't opened, this is not the event we're trying to delete, so return
if (!isPopoverDetailsOpen.value) return
// If the key isn't the delete one, return
if (e.key !== 'Delete') return
handleDelete()
})
})
</script> </script>
<template> <template>
<UiPopover v-model:open="isPopoverDetailsOpen"> <UiPopover v-model:open="isPopoverDetailsOpen">
<UiPopoverTrigger as-child> <UiPopoverTrigger as-child>
<button <button
id="test" class="text-xs px-2 py-1 block w-full text-left rounded-sm focus-visible:bg-red-200"
class="text-xs px-2 py-1 block w-full text-left rounded-sm"
:class=" :class="
cn({ cn({
'text-white bg-slate-600 hover:bg-slate-700': !event.category, 'text-white bg-slate-600 hover:bg-slate-700': !event.category,
@@ -58,6 +83,8 @@ function handleClosePopover() {
'rounded-l-none': isEndEvent 'rounded-l-none': isEndEvent
}) })
" "
@dblclick="handleDoubleClick"
@keydown.delete="handleDelete"
> >
<div class="line-clamp-2 [overflow-wrap:anywhere] hyphens-auto"> <div class="line-clamp-2 [overflow-wrap:anywhere] hyphens-auto">
{{ eventTitle }} {{ eventTitle }}

View File

@@ -86,20 +86,26 @@ function handleCancel() {
</div> </div>
</div> </div>
<footer class="flex gap-2 justify-end"> <footer class="flex gap-2 justify-between">
<UiButton type="button" size="sm" variant="ghost" @click="() => isDeleteEventModalOpen = false">
Retour
</UiButton>
<div class="flex gap-2 justify-end">
<Transition name="fade-delay"> <Transition name="fade-delay">
<UiButton v-if="isLoading" type="button" size="sm" variant="destructive" @click.prevent="handleCancel"> <UiButton v-if="isLoading" type="button" size="sm" variant="destructive" @click.prevent="handleCancel">
Annuler Annuler
</UiButton> </UiButton>
</Transition> </Transition>
<UiButton size="sm" :disabled="isLoading"> <UiButton size="sm" variant="destructive" :disabled="isLoading">
<Transition name="fade"> <Transition name="fade">
<PhCircleNotch v-if="isLoading" size="20" class="animate-spin"/> <PhCircleNotch v-if="isLoading" size="20" class="animate-spin"/>
</Transition> </Transition>
Supprimer Supprimer
</UiButton> </UiButton>
</div>
</footer> </footer>
</form> </form>
</UiAlertDialogContent> </UiAlertDialogContent>

View File

@@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { PhAlarm, PhCircleNotch, PhMapPinArea } from '@phosphor-icons/vue' import { PhAlarm, PhCircleNotch, PhMapPinArea, PhPencilSimpleLine } from '@phosphor-icons/vue'
import { VisuallyHidden } from 'radix-vue' import { VisuallyHidden } from 'radix-vue'
const { isEditEventModalOpen } = storeToRefs(useCalendarEvents()) const { isEditEventModalOpen } = storeToRefs(useCalendarEvents())
@@ -82,7 +82,10 @@ function handleCancel() {
<form @submit.prevent="handleAction"> <form @submit.prevent="handleAction">
<div class="grid grid-cols-2 gap-y-4"> <div class="grid grid-cols-2 gap-y-4">
<div class="col-span-2 ml-8"> <div class="col-span-2">
<div class="flex items-center gap-2">
<PhPencilSimpleLine size="20" weight="fill" />
<input <input
id="new-event-title" id="new-event-title"
v-model="eventSkeleton.title" v-model="eventSkeleton.title"
@@ -90,7 +93,9 @@ function handleCancel() {
name="new-event-title" name="new-event-title"
required required
placeholder="Titre de l'évènement" placeholder="Titre de l'évènement"
class="w-full -my-1 py-1 -mx-1 px-1 text-lg border-b-[1px] bg-transparent focus-visible:outline-none focus-visible:border-blue-600"> class="w-full -my-1 py-1 -mx-1 px-1 text-lg border-b-[1px] bg-transparent focus-visible:outline-none focus-visible:border-blue-600"
>
</div>
</div> </div>
<div class="col-span-2 ml-8"> <div class="col-span-2 ml-8">

View File

@@ -294,7 +294,7 @@ insert into public.calendar_events (title, description, location, start_date, en
1 1
); );
insert into public.calendar_events (title, description, location, start_date, end_date, category, hidden, wiki, calendar_id) values ( insert into public.calendar_events (title, description, location, start_date, end_date, category, hidden, wiki, calendar_id) values (
'Grande Banque Minérale', 'Grande Bourse Minérale',
'Les artisans et mineurs de Rougefer se réunissent pour vendre le fruit de leur dur labeur.', 'Les artisans et mineurs de Rougefer se réunissent pour vendre le fruit de leur dur labeur.',
'Cantane', 'Cantane',
'{ "day": 23, "month": 8, "year": 3209 }', '{ "day": 23, "month": 8, "year": 3209 }',