diff --git a/.changeset/dull-icons-report.md b/.changeset/dull-icons-report.md new file mode 100644 index 00000000..f67d932a --- /dev/null +++ b/.changeset/dull-icons-report.md @@ -0,0 +1,5 @@ +--- +"enspire": patch +--- + +Refactor internal strategy for making API requests diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..c483022c --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +shamefully-hoist=true \ No newline at end of file diff --git a/components/custom/CAS/ClassroomReservation/NewClassroomReservation.vue b/components/custom/CAS/ClassroomReservation/NewClassroomReservation.vue index 3bf11a0d..480e0b2f 100644 --- a/components/custom/CAS/ClassroomReservation/NewClassroomReservation.vue +++ b/components/custom/CAS/ClassroomReservation/NewClassroomReservation.vue @@ -15,12 +15,10 @@ import { enums } from '~/components/custom/enum2str' const { toast } = useToast() -const { data } = await useAsyncData('classroomStatuses', () => { - return $fetch(`/api/reservation/classroomId`, { - headers: useRequestHeaders(), - method: 'GET', - }) +const { data, suspense } = useQuery({ + queryKey: ['/api/reservation/classroomId'], }) +await suspense() if (!data.value) { toast({ @@ -32,12 +30,10 @@ else { data.value = data.value.sort((a: any, b: any) => a.name < b.name ? -1 : 1) } -const { data: clubs } = await useAsyncData('allClubs', () => { - return $fetch(`/api/user/all_clubs`, { - headers: useRequestHeaders(), - method: 'GET', - }) +const { data: clubs, suspense: clubsSuspense } = useQuery({ + queryKey: ['/api/user/all_clubs'], }) +await clubsSuspense() if (!clubs.value) { toast({ diff --git a/components/custom/CAS/Record/NewActivityRecord.vue b/components/custom/CAS/Record/NewActivityRecord.vue index a55caaf5..02446c3b 100644 --- a/components/custom/CAS/Record/NewActivityRecord.vue +++ b/components/custom/CAS/Record/NewActivityRecord.vue @@ -33,10 +33,6 @@ const { toast } = useToast() const selectedClub = ref() -definePageMeta({ - middleware: ['auth'], -}) - const isLoading = ref(false) const formSchema = toTypedSchema(z.object({ @@ -51,12 +47,10 @@ const formSchema = toTypedSchema(z.object({ sTime: z.number().min(0).max(5), })) -const { data } = await useAsyncData('allClubsWithMemberships', async () => { - return await $fetch('/api/user/all_clubs?includeMemberships=true', { - headers: useRequestHeaders(), - method: 'GET', - }) +const { data, suspense } = useQuery({ + queryKey: ['/api/user/all_clubs'], }) +await suspense() if (!data.value) { throw createError({ diff --git a/components/custom/CAS/Record/ViewMyActivityRecords.vue b/components/custom/CAS/Record/ViewMyActivityRecords.vue index 44d105dc..352a1dad 100644 --- a/components/custom/CAS/Record/ViewMyActivityRecords.vue +++ b/components/custom/CAS/Record/ViewMyActivityRecords.vue @@ -1,5 +1,7 @@