11import React , { useEffect , useRef } from 'react'
22
3- function CoursePagePopup ( { isOpen, onClose, course, prerequisiteTree } ) {
3+ function CoursePagePopup ( { favouriteCourses, addFavourite,
4+ removeFavourite, isOpen, onClose, course, prerequisiteTree } ) {
45 const treeRef = useRef ( null ) ;
56 useEffect ( ( ) => {
67 const handleKeyDown = ( event ) => {
@@ -18,6 +19,15 @@ function CoursePagePopup({ isOpen, onClose, course, prerequisiteTree }) {
1819 } ;
1920 } , [ isOpen , onClose ] ) ;
2021
22+
23+ const handleFavouriteClick = ( course ) => {
24+ if ( favouriteCourses . some ( fav => fav . code === course . code ) ) {
25+ removeFavourite ( course ) ;
26+ } else {
27+ addFavourite ( course ) ;
28+ }
29+ } ;
30+
2131 const handleTreeClick = ( ) => {
2232 if ( treeRef . current ) {
2333 treeRef . current . focus ( ) ; // gives it focus
@@ -40,21 +50,23 @@ function CoursePagePopup({ isOpen, onClose, course, prerequisiteTree }) {
4050 < div >
4151 < h2 className = "text-5xl font-extrabold text-[#2e2e4f] " >
4252 < span className = "text-violet-700" > { course . code } </ span > - { course . name }
43- < span className = "ml-4 text-lg text-violet-700" > ({ course . credits } Credits)</ span >
53+ < span className = "ml-4 text-lg text-violet-700 whitespace-nowrap" >
54+ ({ course . credits } Credits)
55+ </ span >
4456 </ h2 >
4557 < div className = "my-6 h-1.5 w-full bg-violet-500" > </ div >
4658 </ div >
4759 < div >
4860 < button
49- className = "text-yellow-500 cursor-pointer"
61+ className = "text-yellow-500 bg-yellow-400 cursor-pointer"
5062 onClick = { ( e ) => {
5163 e . stopPropagation ( ) ; // prevent popup from opening
5264 handleFavouriteClick ( course . code ) ;
5365 } }
5466 >
55- { /* {model. favouriteCourses.includes(course.code)
67+ { favouriteCourses . includes ( course . code )
5668 ? 'Remove from Favourites'
57- : 'Add to Favourites'} */ }
69+ : 'Add to Favourites' }
5870 </ button >
5971 </ div >
6072
0 commit comments