From b6f32e1775fa3e887b914aca40f58e014f4a142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Sun, 22 Sep 2024 18:09:03 +0100 Subject: [PATCH] fix: class shown on schedule is now always the selected ones --- .../sidebar/CoursesController/ClassSelector.tsx | 13 +++++-------- .../ClassSelectorDropdownController.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/planner/sidebar/CoursesController/ClassSelector.tsx b/src/components/planner/sidebar/CoursesController/ClassSelector.tsx index 52db2bf5..a43c9114 100644 --- a/src/components/planner/sidebar/CoursesController/ClassSelector.tsx +++ b/src/components/planner/sidebar/CoursesController/ClassSelector.tsx @@ -17,15 +17,12 @@ const ClassSelector = ({ course }: Props) => { const classSelectorContentRef = useRef(null) const { multipleOptions, setMultipleOptions, selectedOption } = useContext(MultipleOptionsContext) - const [selectedClassId, setSelectedClassId] = useState(null); - const courseOption: CourseOption = multipleOptions[selectedOption].course_options.find((opt) => opt.course_id === course.id) - const [locked, setLocked] = useState(courseOption?.locked) - const [preview, setPreview] = useState(null) const [display, setDisplay] = useState(courseOption?.picked_class_id) + const [isDropdownOpen, setIsDropdownOpen] = useState(false); useEffect(() => { const course_options = multipleOptions[selectedOption].course_options; @@ -88,10 +85,9 @@ const ClassSelector = ({ course }: Props) => {

{/* Dropdown Menu */} - { - if (!open) { - removePreview(); - } + { + setIsDropdownOpen(open); + if (!open) removePreview(); }}>
@@ -111,6 +107,7 @@ const ClassSelector = ({ course }: Props) => { >] + isDropdownOpen: boolean setPreview: Dispatch> - removePreview: () => void, + removePreview: () => void contentRef: any triggerRef: any } @@ -48,6 +49,7 @@ const NoOptionsFound = ({ mobile }: { mobile: boolean }) => { const ClassSelectorDropdownController = ({ course, selectedClassIdHook, + isDropdownOpen, setPreview, removePreview, contentRef, @@ -229,7 +231,7 @@ const ClassSelectorDropdownController = ({ setSelectedClassId(classInfo.id) setPreview(null) }} - onMouseEnter={() => showPreview(classInfo)} + onMouseEnter={() => { if (isDropdownOpen) showPreview(classInfo) }} onMouseLeave={() => removePreview()} /> ))} @@ -263,7 +265,7 @@ const ClassSelectorDropdownController = ({ setSelectedClassId(classInfo.id) setPreview(null) }} - onMouseEnter={() => showPreview(classInfo)} + onMouseEnter={() => { if (isDropdownOpen) showPreview(classInfo) }} onMouseLeave={() => removePreview()} /> ))}