Prevented other popovers from opening when an operation is underway
This commit is contained in:
@@ -3,7 +3,7 @@ import type { RPGDate } from '~/models/Date';
|
|||||||
|
|
||||||
import { PhAlarm, PhCircleNotch, PhMapPinArea } from '@phosphor-icons/vue'
|
import { PhAlarm, PhCircleNotch, PhMapPinArea } from '@phosphor-icons/vue'
|
||||||
|
|
||||||
const { eventSkeleton } = storeToRefs(useCalendarEvents())
|
const { eventSkeleton, operationInProgress } = storeToRefs(useCalendarEvents())
|
||||||
const { resetSkeleton, submitSkeleton, cancelLatestRequest } = useCalendarEvents()
|
const { resetSkeleton, submitSkeleton, cancelLatestRequest } = useCalendarEvents()
|
||||||
const popoverOpen = ref(false)
|
const popoverOpen = ref(false)
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
@@ -21,6 +21,14 @@ const props = defineProps<{
|
|||||||
* Opens event creation's popover
|
* Opens event creation's popover
|
||||||
*/
|
*/
|
||||||
function openEventCreatePopover() {
|
function openEventCreatePopover() {
|
||||||
|
console.log(operationInProgress.value)
|
||||||
|
if (operationInProgress.value) {
|
||||||
|
popoverOpen.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('open still what ?')
|
||||||
|
|
||||||
resetSkeleton()
|
resetSkeleton()
|
||||||
|
|
||||||
popoverOpen.value = true
|
popoverOpen.value = true
|
||||||
@@ -55,7 +63,6 @@ async function handleSubmit() {
|
|||||||
* @param e The closing event (can be keydown or click)
|
* @param e The closing event (can be keydown or click)
|
||||||
*/
|
*/
|
||||||
function handleClosing(e: Event) {
|
function handleClosing(e: Event) {
|
||||||
console.log(e)
|
|
||||||
if (isLoading.value) {
|
if (isLoading.value) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ const eventsNotDisplayed: ComputedRef<number> = computed<number>(() => eventsFo
|
|||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
|
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
<CalendarFormCreateEvent :date btn-class="absolute inset-0 w-full h-full cursor-default z-0" />
|
<LazyCalendarFormCreateEvent :date btn-class="absolute inset-0 w-full h-full cursor-default z-0" />
|
||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -187,6 +187,10 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
* EVENT CREATION FUNCTIONS
|
* EVENT CREATION FUNCTIONS
|
||||||
*/
|
*/
|
||||||
const lastActiveEvent = ref<CalendarEvent | null>()
|
const lastActiveEvent = ref<CalendarEvent | null>()
|
||||||
|
const isCreatingEvent = ref<boolean>(false)
|
||||||
|
const isUpdatingEvent = ref<boolean>(false)
|
||||||
|
const isDeletingEvent = ref<boolean>(false)
|
||||||
|
const operationInProgress = computed(() => isCreatingEvent.value || isUpdatingEvent.value || isDeletingEvent.value)
|
||||||
let abortController: AbortController | null = null
|
let abortController: AbortController | null = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,6 +212,7 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
*/
|
*/
|
||||||
async function submitSkeleton() {
|
async function submitSkeleton() {
|
||||||
abortController = new AbortController()
|
abortController = new AbortController()
|
||||||
|
isCreatingEvent.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch('/api/calendars/events/create', { method: 'POST', body: { event : eventSkeleton.value, calendarId: calendarId.value }, signal: abortController.signal })
|
const res = await $fetch('/api/calendars/events/create', { method: 'POST', body: { event : eventSkeleton.value, calendarId: calendarId.value }, signal: abortController.signal })
|
||||||
@@ -217,17 +222,13 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
} finally {
|
} finally {
|
||||||
abortController = null
|
abortController = null
|
||||||
}
|
isCreatingEvent.value = false
|
||||||
}
|
|
||||||
|
|
||||||
function cancelLatestRequest() {
|
|
||||||
if (abortController) {
|
|
||||||
abortController.abort()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateEventFromSkeleton() {
|
async function updateEventFromSkeleton() {
|
||||||
abortController = new AbortController()
|
abortController = new AbortController()
|
||||||
|
isUpdatingEvent.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch(`/api/calendars/events/${eventSkeleton.value.id}`, { method: 'PATCH', body: { event : eventSkeleton.value, calendarId: calendarId.value }, signal: abortController.signal })
|
const res = await $fetch(`/api/calendars/events/${eventSkeleton.value.id}`, { method: 'PATCH', body: { event : eventSkeleton.value, calendarId: calendarId.value }, signal: abortController.signal })
|
||||||
@@ -238,11 +239,13 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
} finally {
|
} finally {
|
||||||
abortController = null
|
abortController = null
|
||||||
|
isUpdatingEvent.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteEventFromSkeleton() {
|
async function deleteEventFromSkeleton() {
|
||||||
abortController = new AbortController()
|
abortController = new AbortController()
|
||||||
|
isDeletingEvent.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await $fetch(`/api/calendars/events/${eventSkeleton.value.id}`, { method: 'DELETE', signal: abortController.signal })
|
await $fetch(`/api/calendars/events/${eventSkeleton.value.id}`, { method: 'DELETE', signal: abortController.signal })
|
||||||
@@ -253,6 +256,13 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
} finally {
|
} finally {
|
||||||
abortController = null
|
abortController = null
|
||||||
|
isDeletingEvent.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelLatestRequest() {
|
||||||
|
if (abortController) {
|
||||||
|
abortController.abort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +273,10 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
getRelativeEventFromDate,
|
getRelativeEventFromDate,
|
||||||
getRelativeEventFromEvent,
|
getRelativeEventFromEvent,
|
||||||
cancelLatestRequest,
|
cancelLatestRequest,
|
||||||
|
isCreatingEvent,
|
||||||
|
isUpdatingEvent,
|
||||||
|
isDeletingEvent,
|
||||||
|
operationInProgress,
|
||||||
eventSkeleton,
|
eventSkeleton,
|
||||||
resetSkeleton,
|
resetSkeleton,
|
||||||
submitSkeleton,
|
submitSkeleton,
|
||||||
|
|||||||
Reference in New Issue
Block a user