Added loading logic to calendar page

This commit is contained in:
Alexis
2024-05-17 20:50:45 +02:00
parent 5dd06ea3f8
commit 059edd6fc1
3 changed files with 32 additions and 20 deletions

View File

@@ -1,16 +1,14 @@
<script lang="ts" setup>
import type { MenuItem } from '~/components/global/SidebarProps';
const user = useSupabaseUser()
useHead({
title: 'Calendrier'
})
definePageMeta({
middleware: ['auth-guard']
})
const user = useSupabaseUser()
// Redirect user back home when they log out on the page
watch(user, (n, _o) => {
if (!n) {
@@ -19,12 +17,33 @@ watch(user, (n, _o) => {
})
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>
<template>
<div class="h-full grid grid-cols-[auto_1fr]">
<Sidebar :menu-items="sidebarMenu" />
<CalendarDashboard />
<template v-if="pending">
Loading
</template>
<template v-else>
<Calendar />
</template>
</div>
</template>