From 19a71d356eb55d1acfd90849b09f9351817a3511 Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sat, 24 Aug 2024 14:01:16 +0200 Subject: [PATCH] Fixed horrible loading pattern for calendar --- components/calendar/Calendar.vue | 13 +++++++++---- nuxt.config.ts | 3 --- pages/i/calendar/[id].vue | 29 ++++++++++++++++++++++++++--- pages/i/world/[id].vue | 2 +- server/api/calendars/query.get.ts | 2 +- stores/CalendarStore.ts | 24 +++++++++--------------- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/components/calendar/Calendar.vue b/components/calendar/Calendar.vue index fe4c5a4..b2b10bf 100644 --- a/components/calendar/Calendar.vue +++ b/components/calendar/Calendar.vue @@ -8,11 +8,16 @@ import CenturyLayout from './state/centennially/Layout.vue' import DecadeLayout from './state/decennially/Layout.vue' import YearLayout from './state/yearly/Layout.vue' -const route = useRoute() -const id = route.params.id -const calendarStore = useCalendar() +import type { Calendar } from '~/models/CalendarConfig' +import type { Category } from '~/models/Category' -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() diff --git a/nuxt.config.ts b/nuxt.config.ts index 04956d5..c0eea6e 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -28,8 +28,5 @@ export default defineNuxtConfig({ preference: 'dark', fallback: 'dark', }, - supabase: { - redirect: false - }, eslint: {} }) diff --git a/pages/i/calendar/[id].vue b/pages/i/calendar/[id].vue index 3611527..c411df1 100644 --- a/pages/i/calendar/[id].vue +++ b/pages/i/calendar/[id].vue @@ -1,5 +1,7 @@ diff --git a/pages/i/world/[id].vue b/pages/i/world/[id].vue index 9a23c26..77ea925 100644 --- a/pages/i/world/[id].vue +++ b/pages/i/world/[id].vue @@ -5,7 +5,7 @@ import type { World } from '~/models/World'; const route = useRoute() 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 diff --git a/server/api/calendars/query.get.ts b/server/api/calendars/query.get.ts index 2617fa2..9a5b5e2 100644 --- a/server/api/calendars/query.get.ts +++ b/server/api/calendars/query.get.ts @@ -46,7 +46,7 @@ export default defineEventHandler(async (event) => { } if (query.id) { - return output.eq('id', query.id).single() + return output.eq('id', query.id).limit(1).single() } return output.returns() diff --git a/stores/CalendarStore.ts b/stores/CalendarStore.ts index 48f240d..4a055b5 100644 --- a/stores/CalendarStore.ts +++ b/stores/CalendarStore.ts @@ -1,6 +1,6 @@ -import { - type RPGDate, - type RPGDateOrder, +import type { + RPGDate, + RPGDateOrder, } from '@/models/Date' import { useUrlSearchParams } from '@vueuse/core' import { defineStore } from 'pinia' @@ -25,10 +25,6 @@ type CalendarCurrentDate = { } export const useCalendar = defineStore('calendar', () => { - const params = useUrlSearchParams('history', { - write: false - }) - /** * Static calendar config */ @@ -47,14 +43,8 @@ export const useCalendar = defineStore('calendar', () => { */ const months = ref([]) - async function fetchCalendar(id: number) { + function setActiveCalendar(calendarData: Calendar, categoryData: Category[]) { 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 activeCalendar.value = { @@ -85,6 +75,10 @@ export const useCalendar = defineStore('calendar', () => { } } + const params = useUrlSearchParams('history', { + write: false + }) + /** * Sorted month data using the raw months */ @@ -873,7 +867,7 @@ export const useCalendar = defineStore('calendar', () => { } return { - fetchCalendar, + setActiveCalendar, activeCalendar, months, sortedMonths,