From 37847cd3f81f334743245389ac7c85c18f776280 Mon Sep 17 00:00:00 2001 From: ImJustChew Date: Sat, 4 Nov 2023 17:05:12 +0800 Subject: [PATCH] cds ui update and removed bottleneck --- src/app/[lang]/cds/CdsCourseForm.tsx | 3 +-- src/app/[lang]/cds/CdsFormContainer.tsx | 15 +++++++-------- src/app/[lang]/cds/page.tsx | 4 +++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/[lang]/cds/CdsCourseForm.tsx b/src/app/[lang]/cds/CdsCourseForm.tsx index cf4bb871..9bf7bf2a 100644 --- a/src/app/[lang]/cds/CdsCourseForm.tsx +++ b/src/app/[lang]/cds/CdsCourseForm.tsx @@ -80,8 +80,7 @@ type CdsCoursesFormFields = { const CdsCoursesForm: FC<{ initialSubmission: { preferences: CdsCourseDefinition[] }; - cdsCoursesList: CdsCourseDefinition[]; -}> = ({ initialSubmission, cdsCoursesList }) => { +}> = ({ initialSubmission }) => { const supabase = useSupabaseClient(); const [selectedCourses, setSelectedCourses] = useState(initialSubmission.preferences); const [open, setOpen] = useState(false); diff --git a/src/app/[lang]/cds/CdsFormContainer.tsx b/src/app/[lang]/cds/CdsFormContainer.tsx index 2e25633e..2c963924 100644 --- a/src/app/[lang]/cds/CdsFormContainer.tsx +++ b/src/app/[lang]/cds/CdsFormContainer.tsx @@ -6,20 +6,19 @@ import { useMemo } from 'react'; const CdsFormContainer = () => { const supabase = useSupabaseClient(); - const { data: courses, error, isLoading } = useSWR(['cds_courses'], async () => { - const { data = [], error } = await supabase.from('cds_courses').select('*'); - if(error) throw error; - return data; - }) - //assuming preferences is a string of raw_id const preferences: string[] = []; - const preferenceCourses = useMemo(() => courses?.filter(course => preferences.includes(course.raw_id!)) ?? [], [courses]); + + const { data: preferenceCourses = [], error, isLoading } = useSWR(['cds_courses'], async () => { + const { data = [], error } = await supabase.from('cds_courses').select('*').in('raw_id', preferences); + if(error) throw error; + return data ?? []; + }) if(isLoading) return return (
- +
) } diff --git a/src/app/[lang]/cds/page.tsx b/src/app/[lang]/cds/page.tsx index a730ebbc..849c4f21 100644 --- a/src/app/[lang]/cds/page.tsx +++ b/src/app/[lang]/cds/page.tsx @@ -8,6 +8,7 @@ import { signIn, useSession } from "next-auth/react" import { FC, useState } from "react" import useSWR from "swr"; import CdsFormContainer from "./CdsFormContainer"; +import { useSettings } from "@/hooks/contexts/settings"; const CdsFormBeforeSignIn: FC<{ isLoggingIn: boolean }> = ({ isLoggingIn }) => { return
@@ -17,13 +18,14 @@ const CdsFormBeforeSignIn: FC<{ isLoggingIn: boolean }> = ({ isLoggingIn }) => { const CourseDemandSurvey = () => { const { data, status, update } = useSession(); + const { darkMode } = useSettings(); console.log(data, status); // if(true) return - return
+ return

選課意願調查