Fixed horrible loading pattern for calendar

This commit is contained in:
Alexis
2024-08-24 14:01:16 +02:00
parent 23e996ee2e
commit 19a71d356e
6 changed files with 46 additions and 27 deletions

View File

@@ -8,11 +8,16 @@ 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 route = useRoute() import type { Calendar } from '~/models/CalendarConfig'
const id = route.params.id import type { Category } from '~/models/Category'
const calendarStore = useCalendar()
await calendarStore.fetchCalendar(Number(id)) const props = defineProps<{
calendarData: Calendar,
categories: Category[]
}>()
const { setActiveCalendar } = useCalendar()
setActiveCalendar(props.calendarData, props.categories)
const { currentConfig, jumpToDate, selectedDate } = useCalendar() const { currentConfig, jumpToDate, selectedDate } = useCalendar()

View File

@@ -28,8 +28,5 @@ export default defineNuxtConfig({
preference: 'dark', preference: 'dark',
fallback: 'dark', fallback: 'dark',
}, },
supabase: {
redirect: false
},
eslint: {} eslint: {}
}) })

View File

@@ -1,5 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { PhCircleNotch } from '@phosphor-icons/vue'; import { PhCircleNotch } from '@phosphor-icons/vue';
import type { Calendar } from '~/models/CalendarConfig';
import type { Category } from '~/models/Category';
useHead({ useHead({
title: 'Calendrier' title: 'Calendrier'
@@ -15,11 +17,32 @@ watch(user, (n, _o) => {
navigateTo('/') navigateTo('/')
} }
}) })
const route = useRoute()
const id = route.params.id
const { data: calendarData, pending: calPending } = useLazyFetch('/api/calendars/query', { query: { id, full: true } })
const { data: catData, pending: catPending } = useLazyFetch('/api/calendars/categories/query')
const cal = computed<Calendar>(() => calendarData?.value?.data as Calendar)
const categories = computed<Category[]>(() => catData?.value?.data as Category[])
</script> </script>
<template> <template>
<Suspense> <div v-if="calPending || catPending" class="h-full w-full grid place-items-center">
<LazyCalendar /> <div class="grid gap-2 justify-items-center opacity-50">
<p>Chargement du calendrier</p>
<PhCircleNotch size="50" class="animate-spin"/>
</div>
</div>
<Calendar v-else-if="cal && categories" :calendar-data="cal" :categories />
<!-- <span v-if="calendarData && categories">
<Calendar :calendar-data :categories />
</span> -->
<!-- <Suspense>
<Calendar :calendar="calendar?.data" :categories />
<template #fallback> <template #fallback>
<div class="h-full w-full grid place-items-center"> <div class="h-full w-full grid place-items-center">
@@ -29,5 +52,5 @@ watch(user, (n, _o) => {
</div> </div>
</div> </div>
</template> </template>
</Suspense> </Suspense> -->
</template> </template>

View File

@@ -5,7 +5,7 @@ import type { World } from '~/models/World';
const route = useRoute() const route = useRoute()
const id = route.params.id const id = route.params.id
const { data: res, pending } = await useFetch(`/api/worlds/query`, { query: { id, full: true } }) const { data: res, pending } = await useFetch('/api/worlds/query', { query: { id, full: true } })
const world = res.value?.data as World const world = res.value?.data as World

View File

@@ -46,7 +46,7 @@ export default defineEventHandler(async (event) => {
} }
if (query.id) { if (query.id) {
return output.eq('id', query.id).single<Calendar>() return output.eq('id', query.id).limit(1).single<Calendar>()
} }
return output.returns<Calendar[]>() return output.returns<Calendar[]>()

View File

@@ -1,6 +1,6 @@
import { import type {
type RPGDate, RPGDate,
type RPGDateOrder, RPGDateOrder,
} from '@/models/Date' } from '@/models/Date'
import { useUrlSearchParams } from '@vueuse/core' import { useUrlSearchParams } from '@vueuse/core'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
@@ -25,10 +25,6 @@ type CalendarCurrentDate = {
} }
export const useCalendar = defineStore('calendar', () => { export const useCalendar = defineStore('calendar', () => {
const params = useUrlSearchParams('history', {
write: false
})
/** /**
* Static calendar config * Static calendar config
*/ */
@@ -47,14 +43,8 @@ export const useCalendar = defineStore('calendar', () => {
*/ */
const months = ref<CalendarMonth[]>([]) const months = ref<CalendarMonth[]>([])
async function fetchCalendar(id: number) { function setActiveCalendar(calendarData: Calendar, categoryData: Category[]) {
try { try {
const res = await $fetch('/api/calendars/query', { query: { id, full: true } })
const categoryRes = await $fetch('/api/calendars/categories/query')
const calendarData = res.data as Calendar
const categoryData = categoryRes.data as Category[]
if (!calendarData.id) return if (!calendarData.id) return
activeCalendar.value = { activeCalendar.value = {
@@ -85,6 +75,10 @@ export const useCalendar = defineStore('calendar', () => {
} }
} }
const params = useUrlSearchParams('history', {
write: false
})
/** /**
* Sorted month data using the raw months * Sorted month data using the raw months
*/ */
@@ -873,7 +867,7 @@ export const useCalendar = defineStore('calendar', () => {
} }
return { return {
fetchCalendar, setActiveCalendar,
activeCalendar, activeCalendar,
months, months,
sortedMonths, sortedMonths,