Skip to content

Commit

Permalink
fix: class shown on schedule is now always the selected ones
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Sep 22, 2024
1 parent 7fe89f1 commit b6f32e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ const ClassSelector = ({ course }: Props) => {
const classSelectorContentRef = useRef(null)

const { multipleOptions, setMultipleOptions, selectedOption } = useContext(MultipleOptionsContext)

const [selectedClassId, setSelectedClassId] = useState<number | null>(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<number | null>(null)
const [display, setDisplay] = useState(courseOption?.picked_class_id)
const [isDropdownOpen, setIsDropdownOpen] = useState(false);

useEffect(() => {
const course_options = multipleOptions[selectedOption].course_options;
Expand Down Expand Up @@ -88,10 +85,9 @@ const ClassSelector = ({ course }: Props) => {
</p>
<div className="flex items-center">
{/* Dropdown Menu */}
<DropdownMenu onOpenChange={(open: boolean) => {
if (!open) {
removePreview();
}
<DropdownMenu open={isDropdownOpen} onOpenChange={(open: boolean) => {
setIsDropdownOpen(open);
if (!open) removePreview();
}}>
<div className="w-full">
<DropdownMenuTrigger asChild disabled={courseOption?.locked} ref={classSelectorTriggerRef}>
Expand All @@ -111,6 +107,7 @@ const ClassSelector = ({ course }: Props) => {
<ClassSelectorDropdownController
course={course}
selectedClassIdHook={[selectedClassId, setSelectedClassId]}
isDropdownOpen={isDropdownOpen}
setPreview={setPreview}
removePreview={removePreview}
contentRef={classSelectorContentRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import ProfessorItem from "./ProfessorItem";
type Props = {
course: CourseInfo
selectedClassIdHook: [number | null, Dispatch<SetStateAction<number | null>>]
isDropdownOpen: boolean
setPreview: Dispatch<SetStateAction<number | null>>
removePreview: () => void,
removePreview: () => void
contentRef: any
triggerRef: any
}
Expand Down Expand Up @@ -48,6 +49,7 @@ const NoOptionsFound = ({ mobile }: { mobile: boolean }) => {
const ClassSelectorDropdownController = ({
course,
selectedClassIdHook,
isDropdownOpen,
setPreview,
removePreview,
contentRef,
Expand Down Expand Up @@ -229,7 +231,7 @@ const ClassSelectorDropdownController = ({
setSelectedClassId(classInfo.id)
setPreview(null)
}}
onMouseEnter={() => showPreview(classInfo)}
onMouseEnter={() => { if (isDropdownOpen) showPreview(classInfo) }}
onMouseLeave={() => removePreview()}
/>
))}
Expand Down Expand Up @@ -263,7 +265,7 @@ const ClassSelectorDropdownController = ({
setSelectedClassId(classInfo.id)
setPreview(null)
}}
onMouseEnter={() => showPreview(classInfo)}
onMouseEnter={() => { if (isDropdownOpen) showPreview(classInfo) }}
onMouseLeave={() => removePreview()}
/>
))}
Expand Down

0 comments on commit b6f32e1

Please sign in to comment.