Skip to content

Commit

Permalink
fix: remove hovered course on unmount (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 authored Feb 11, 2024
1 parent 38e2523 commit 8a4bfe6
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ import Grades from '$lib/grades';
import analyticsEnum from '$lib/analytics';
import { openSnackbar } from '$actions/AppStoreActions';
import WebSOC from '$lib/websoc';
import { useHoveredStore } from '$stores/HoveredStore';

function getColors() {
const courseColors = AppStore.schedule.getCurrentCourses().reduce((accumulator, { section }) => {
accumulator[section.sectionCode] = section.color;
return accumulator;
}, {} as { [key: string]: string });
const courseColors = AppStore.schedule.getCurrentCourses().reduce(
(accumulator, { section }) => {
accumulator[section.sectionCode] = section.color;
return accumulator;
},
{} as { [key: string]: string }
);

return courseColors;
}
Expand Down Expand Up @@ -174,6 +178,8 @@ export default function CourseRenderPane(props: { id?: number }) {
const [error, setError] = useState(false);
const [scheduleNames, setScheduleNames] = useState(AppStore.getScheduleNames());

const setHoveredCourseEvents = useHoveredStore((store) => store.setHoveredCourseEvents);

const loadCourses = useCallback(async () => {
setLoading(true);

Expand Down Expand Up @@ -253,6 +259,17 @@ export default function CourseRenderPane(props: { id?: number }) {
};
}, [loadCourses, props.id]);

/**
* Removes hovered course when component unmounts
* Handles edge cases where the Section Table is removed, rather than the mouse
* ex: Swapping to the Added tab, clicking the LocationCell link
*/
useEffect(() => {
return () => {
setHoveredCourseEvents(undefined);
};
}, [setHoveredCourseEvents]);

return (
<>
{loading ? (
Expand Down

0 comments on commit 8a4bfe6

Please sign in to comment.