diff --git a/apps/frontend/src/components/SectionSelector.tsx b/apps/frontend/src/components/SectionSelector.tsx index c9d3069..077a2b5 100644 --- a/apps/frontend/src/components/SectionSelector.tsx +++ b/apps/frontend/src/components/SectionSelector.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import { useAppDispatch, useAppSelector } from "~/app/hooks"; import { ChevronUpDownIcon } from "@heroicons/react/24/outline"; import { Listbox, RadioGroup } from "@headlessui/react"; @@ -17,13 +17,13 @@ import { FlushedButton } from "~/components/Buttons"; const SectionSelector = ({ courseIDs }: { courseIDs: string[] }) => { const dispatch = useAppDispatch(); - const CourseDetails = useFetchCourseInfos(courseIDs); + const courseDetails = useFetchCourseInfos(courseIDs); const selectedSession = useAppSelector(selectSessionInActiveSchedule); const selectedCourseSessions = useAppSelector(selectCourseSessionsInActiveSchedule); const scheduleView = useAppSelector((state) => state.user.scheduleView); - const semesters = [...new Set(CourseDetails.flatMap(course => { + const semesters = [...new Set(courseDetails.flatMap(course => { const schedules: Schedule[] = course.schedules; if (schedules) { return schedules.map(schedule => sessionToString(schedule)); @@ -32,6 +32,19 @@ const SectionSelector = ({ courseIDs }: { courseIDs: string[] }) => { return compareSessions(stringToSession(a || ""), stringToSession(b || "")); }); + const coursesNotInSemester = courseIDs.filter((courseID) => { + const course = courseDetails.find(course => course.courseID === courseID); + const schedules: Schedule[] = course?.schedules || []; + return !schedules.some(schedule => sessionToString(schedule) === selectedSession); + }); + + useEffect(() => { + // Check if selected session is in the list of semesters + if (selectedSession.length > 0 && !semesters.includes(selectedSession)) { + dispatch(userSchedulesSlice.actions.updateActiveScheduleSession(stringToSession(""))); + } + }, [selectedSession, semesters]) + return (