Fixed loading error with calendar store
This commit is contained in:
@@ -7,11 +7,35 @@ import CenturyLayout from './state/centennially/Layout.vue'
|
|||||||
import DecadeLayout from './state/decennially/Layout.vue'
|
import DecadeLayout from './state/decennially/Layout.vue'
|
||||||
import YearLayout from './state/yearly/Layout.vue'
|
import YearLayout from './state/yearly/Layout.vue'
|
||||||
|
|
||||||
const { currentConfig } = useCalendar()
|
const route = useRoute()
|
||||||
const { selectedDate, jumpToDate } = useCalendar()
|
const worldId = route.params.id
|
||||||
|
|
||||||
const { fetchEvents } = useCalendarEvents()
|
const { setMonths, currentConfig, selectedDate, jumpToDate } = useCalendar()
|
||||||
fetchEvents()
|
const { setEvents } = useCalendarEvents()
|
||||||
|
|
||||||
|
const { data: calendar, pending, refresh } = await useLazyFetch(`/api/calendars/query?world_id=${worldId}`)
|
||||||
|
|
||||||
|
if (!calendar.value) {
|
||||||
|
await refresh()
|
||||||
|
} else {
|
||||||
|
if (calendar.value?.data?.months) {
|
||||||
|
setMonths(calendar.value?.data?.months)
|
||||||
|
}
|
||||||
|
if (calendar.value?.data?.events) {
|
||||||
|
setEvents(calendar.value?.data?.events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(pending, (newStatus) => {
|
||||||
|
if (!newStatus) {
|
||||||
|
if (calendar.value?.data?.months) {
|
||||||
|
setMonths(calendar.value?.data?.months)
|
||||||
|
}
|
||||||
|
if (calendar.value?.data?.events) {
|
||||||
|
setEvents(calendar.value?.data?.events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const currentViewComponent: ComputedRef<Component> = computed<Component>(() => {
|
const currentViewComponent: ComputedRef<Component> = computed<Component>(() => {
|
||||||
switch (currentConfig.viewType) {
|
switch (currentConfig.viewType) {
|
||||||
@@ -36,11 +60,20 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="h-full grid grid-rows-[auto,1fr]">
|
<div class="h-full">
|
||||||
<CalendarMenu />
|
<template v-if="pending">
|
||||||
|
<div class="h-full grid place-items-center">
|
||||||
|
Loading notamment
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="h-full grid grid-rows-[auto,1fr]">
|
||||||
|
<CalendarMenu />
|
||||||
|
|
||||||
<KeepAlive>
|
<KeepAlive>
|
||||||
<component :is="currentViewComponent" />
|
<component :is="currentViewComponent"/>
|
||||||
</KeepAlive>
|
</KeepAlive>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -2,11 +2,6 @@
|
|||||||
import { useCalendar } from '@/stores/CalendarStore'
|
import { useCalendar } from '@/stores/CalendarStore'
|
||||||
|
|
||||||
import { PhMagnifyingGlass } from '@phosphor-icons/vue'
|
import { PhMagnifyingGlass } from '@phosphor-icons/vue'
|
||||||
import CalendarMenuNav from './CalendarMenuNav.vue'
|
|
||||||
import CalendarMenuSubnav from './CalendarMenuSubnav.vue'
|
|
||||||
import CalendarMenuToday from './CalendarMenuToday.vue'
|
|
||||||
import CalendarSwitch from './CalendarSwitch.vue'
|
|
||||||
import CalendarCurrentDate from './CalendarCurrentDate.vue'
|
|
||||||
|
|
||||||
const { revealAdvancedSearch } = useCalendar()
|
const { revealAdvancedSearch } = useCalendar()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -17,33 +17,12 @@ watch(user, (n, _o) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const sidebarMenu: MenuItem[] = []
|
const sidebarMenu: MenuItem[] = []
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const worldId = route.params.id
|
|
||||||
|
|
||||||
const { setMonths } = useCalendar()
|
|
||||||
const { months } = storeToRefs(useCalendar())
|
|
||||||
|
|
||||||
const { data: calendar, pending, refresh } = await useLazyFetch(`/api/calendars/query?world_id=${worldId}`)
|
|
||||||
|
|
||||||
if (calendar.value?.data?.months) {
|
|
||||||
if (!calendar.value) {
|
|
||||||
await refresh()
|
|
||||||
} else {
|
|
||||||
setMonths(calendar.value?.data?.months)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="h-full grid grid-cols-[auto_1fr]">
|
<div class="h-full grid grid-cols-[auto_1fr]">
|
||||||
<Sidebar :menu-items="sidebarMenu" />
|
<Sidebar :menu-items="sidebarMenu" />
|
||||||
|
|
||||||
<template v-if="pending">
|
<Calendar />
|
||||||
Loading là
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
|
||||||
<Calendar />
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -256,7 +256,11 @@ export const useCalendar = defineStore('calendar', () => {
|
|||||||
*/
|
*/
|
||||||
function getMonthName(monthNumber: number): string {
|
function getMonthName(monthNumber: number): string {
|
||||||
const index = Number(monthNumber)
|
const index = Number(monthNumber)
|
||||||
return sortedMonths.value[index].name
|
if (sortedMonths.value[index]) {
|
||||||
|
return sortedMonths.value[index].name
|
||||||
|
}
|
||||||
|
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
const { currentDate, currentConfig } = useCalendar()
|
const { currentDate, currentConfig } = useCalendar()
|
||||||
|
|
||||||
const baseEvents = ref<CalendarEvent[]>([])
|
const baseEvents = ref<CalendarEvent[]>([])
|
||||||
const eventsAreLoading = ref<boolean>(false)
|
|
||||||
const eventsLoaded = ref<boolean>(false)
|
function setEvents(data: CalendarEvent[]) {
|
||||||
|
baseEvents.value = data
|
||||||
|
}
|
||||||
|
|
||||||
const allEvents = computed(() => baseEvents.value.sort((a, b) => {
|
const allEvents = computed(() => baseEvents.value.sort((a, b) => {
|
||||||
return compareDates(a.startDate, b.startDate, 'desc')
|
return compareDates(a.startDate, b.startDate, 'desc')
|
||||||
@@ -23,22 +25,6 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
currentEvents.value = computeCurrentEvents()
|
currentEvents.value = computeCurrentEvents()
|
||||||
})
|
})
|
||||||
|
|
||||||
async function fetchEvents() {
|
|
||||||
try {
|
|
||||||
eventsAreLoading.value = true
|
|
||||||
const fetched = await useFetch<CalendarEvent[]>('/api/events')
|
|
||||||
|
|
||||||
if (fetched.data.value) {
|
|
||||||
eventsLoaded.value = true
|
|
||||||
baseEvents.value = fetched.data.value
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
} finally {
|
|
||||||
eventsAreLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the event can appear in the front end
|
* Determines if the event can appear in the front end
|
||||||
*
|
*
|
||||||
@@ -210,5 +196,5 @@ export const useCalendarEvents = defineStore('calendar-events', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { allEvents, eventsAreLoading, eventsLoaded, currentEvents, fetchEvents, getRelativeEventFromDate, getRelativeEventFromEvent }
|
return { allEvents, setEvents, currentEvents, getRelativeEventFromDate, getRelativeEventFromEvent }
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user