From b0d47a7e72d3f0db19fda34df69ae4cfb9322fdf Mon Sep 17 00:00:00 2001 From: Xavier Lien Date: Fri, 29 Nov 2024 19:00:42 -0500 Subject: [PATCH] Fixed updateUnits (but it goes away on refresh) --- apps/frontend/src/components/ScheduleData.tsx | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/frontend/src/components/ScheduleData.tsx b/apps/frontend/src/components/ScheduleData.tsx index 6940a84..131c434 100644 --- a/apps/frontend/src/components/ScheduleData.tsx +++ b/apps/frontend/src/components/ScheduleData.tsx @@ -12,6 +12,8 @@ import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/20/solid"; import { useFetchCourseInfos } from "~/app/api/course"; import { useFetchFCEInfosByCourse } from "~/app/api/fce"; import { useAuth } from "@clerk/nextjs"; +import { useQueryClient } from "@tanstack/react-query"; +import { Course } from "~/app/types"; type ScheduleDataProps = { scheduled: string[]; @@ -19,6 +21,7 @@ type ScheduleDataProps = { const ScheduleData = ({ scheduled }: ScheduleDataProps) => { const dispatch = useAppDispatch(); + const queryClient = useQueryClient(); const active = useAppSelector((state) => state.schedules.active); const selected = useAppSelector(selectSelectedCoursesInActiveSchedule); @@ -80,6 +83,18 @@ const ScheduleData = ({ scheduled }: ScheduleDataProps) => { ); }; + const updateManualUnits = (courseID: string, manualUnits: string) => { + queryClient.setQueryData( + ["courseInfo", { courseID }], + (oldData: Course) => { + return { + ...oldData, + manualUnits, + }; + } + ); + }; + return ( <>
@@ -162,15 +177,14 @@ const ScheduleData = ({ scheduled }: ScheduleDataProps) => { ? displayUnits(result.manualUnits) : displayUnits(result.units) } - // TODO: Fix updateUnits - // onChange={(e) => - // dispatch( - // cacheSlice.actions.updateUnits({ - // courseID: result.courseID, - // units: e.target.value, - // }) - // ) - // } + onClick={() => { + if (result.manualUnits === undefined) { + updateManualUnits(result.courseID, ""); + } + }} + onChange={(e) => + updateManualUnits(result.courseID, e.target.value) + } placeholder="Units" /> ) : (