diff --git a/src/components/PlannerComponents/PlannerCourse.tsx b/src/components/PlannerComponents/PlannerCourse.tsx index 55f944e..a72e81d 100644 --- a/src/components/PlannerComponents/PlannerCourse.tsx +++ b/src/components/PlannerComponents/PlannerCourse.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState, useEffect, useRef } from "react"; import { MdDragIndicator, MdOutlineMoreHoriz } from "react-icons/md"; import { CourseType } from "../../types/interfaces/Course.interface"; @@ -7,33 +7,79 @@ interface PlannerCourseProps { } const PlannerCourse: React.FC = ({ course }) => { + const [openPopup, setOpenPopup] = useState(false); + const componentRef = useRef(null); + + const togglePopup = (event: React.MouseEvent) => { + event.stopPropagation(); + setOpenPopup((prev) => !prev); + }; + + const handleClickOutside = (event: MouseEvent) => { + if ( + componentRef.current && + event.target instanceof Node && + !componentRef.current.contains(event.target) + ) { + setOpenPopup(false); + } + }; + + useEffect(() => { + document.addEventListener("mousedown", handleClickOutside); + return () => { + document.removeEventListener("mousedown", handleClickOutside); + }; + }, []); + return ( - <> -
-
-
- -
- - {course.department} - {course.code} - -

{course.name}

-
+
+
+
+ +
+ + {course.department} + {course.code} + +

{course.name}

-
-
-

{course.credits}

-
- +
+
+
+

{course.credits}

+
- + + {/* Popup Menu */} + {openPopup && ( +
+
+ + +
+ + +
+
+ )} +
); };