Skip to content

Commit

Permalink
Fixed updateUnits (but it goes away on refresh)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavilien committed Nov 30, 2024
1 parent 2416be7 commit b0d47a7
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions apps/frontend/src/components/ScheduleData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ 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[];
};

const ScheduleData = ({ scheduled }: ScheduleDataProps) => {
const dispatch = useAppDispatch();
const queryClient = useQueryClient();

const active = useAppSelector((state) => state.schedules.active);
const selected = useAppSelector(selectSelectedCoursesInActiveSchedule);
Expand Down Expand Up @@ -80,6 +83,18 @@ const ScheduleData = ({ scheduled }: ScheduleDataProps) => {
);
};

const updateManualUnits = (courseID: string, manualUnits: string) => {
queryClient.setQueryData(
["courseInfo", { courseID }],
(oldData: Course) => {
return {
...oldData,
manualUnits,
};
}
);
};

return (
<>
<div className="flex items-end justify-between">
Expand Down Expand Up @@ -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"
/>
) : (
Expand Down

0 comments on commit b0d47a7

Please sign in to comment.