@@ -8,60 +8,74 @@ function ListView(props) {
88
99 const toggleReadMore = ( courseCode ) => {
1010 setReadMoreState ( prevState => (
11- { ...prevState , [ courseCode ] : ! prevState [ courseCode ] } ) ) ;
11+ { ...prevState , [ courseCode ] : ! prevState [ courseCode ] }
12+ ) ) ;
1213 } ;
1314
14- const handleFavouriteClick = ( courseCode ) => {
15- if ( props . favouriteCourses . includes ( courseCode ) ) {
16- props . removeFavourite ( courseCode ) ;
17- }
18- else {
19- props . addFavourite ( courseCode ) ;
15+ const handleFavouriteClick = ( course ) => {
16+ if ( props . favouriteCourses . some ( fav => fav . code === course . code ) ) {
17+ props . removeFavourite ( course ) ;
18+ } else {
19+ props . addFavourite ( course ) ;
2020 }
2121 } ;
2222
2323 return (
2424 < div className = "relative bg-white text-black p-2 flex flex-col gap-5 h-full overflow-auto" >
25- {
26- coursesToDisplay . length > 0 ?
27- coursesToDisplay . map ( ( course ) => (
28- < div
29- key = { course . code }
30- className = "p-5 hover:bg-blue-100 flex items-center border border-b-black border-solid w-full rounded-lg cursor-pointer" >
25+ { coursesToDisplay . length > 0 ? (
26+ coursesToDisplay . map ( ( course ) => (
27+ < div
28+ key = { course . code }
29+ className = "p-5 hover:bg-blue-100 flex items-center border border-b-black border-solid w-full rounded-lg cursor-pointer"
30+ >
31+ < div >
32+ < p className = "font-bold text-[#000061]" > { course . code } </ p >
33+ < p className = "font-bold" > { course . name } </ p >
34+ < p
35+ className = "text-gray-600"
36+ dangerouslySetInnerHTML = { {
37+ __html : readMoreState [ course . code ]
38+ ? course . description
39+ : course . description . slice ( 0 , 150 ) ,
40+ } }
41+ />
42+ { course . description . length > 150 && (
43+ < span
44+ className = "text-blue-500 cursor-pointer"
45+ onClick = { ( ) => toggleReadMore ( course . code ) }
46+ >
47+ { readMoreState [ course . code ]
48+ ?
49+ ' show less'
50+ :
51+ ' read more' }
52+ </ span >
53+ ) }
3154 < div >
32- < p className = { "font-bold text-[#000061]" } > { course . code } </ p >
33- < p className = "font-bold" > { course . name } </ p >
34- < p className = "text-gray-600" dangerouslySetInnerHTML = {
35- { __html : readMoreState [ course . code ] ? course . description : course . description . slice ( 0 , 150 ) }
36- }
37- />
38- { course . description . length > 150 && (
39- < span className = "text-blue-500" onClick = { ( ) => toggleReadMore ( course . code ) } >
40- { readMoreState [ course . code ] ? ' show less' : 'read more' }
41- </ span >
42- ) }
43-
44- < div >
45- < button className = "text-yellow-500 cursor-pointer" onClick = { ( ) => handleFavouriteClick ( course . code ) } >
46- { props . favouriteCourses . includes ( course . code )
47- ?
48- 'Remove from Favourites'
49- :
50- 'Add to Favourites'
51- }
52- </ button >
53- </ div >
55+ < button
56+ className = "text-yellow-500 cursor-pointer"
57+ onClick = { ( ) => handleFavouriteClick ( course ) }
58+ >
59+ { props . favouriteCourses . some ( fav => fav . code === course . code )
60+ ?
61+ 'Unfavourite'
62+ :
63+ 'Favourite'
64+ }
65+ </ button >
5466 </ div >
5567 </ div >
56- ) ) :
57- < Quantum
58- size = "1000"
59- speed = "2"
60- color = "#000061"
61- />
62- }
68+ </ div >
69+ ) )
70+ ) : (
71+ < Quantum
72+ size = "1000"
73+ speed = "2"
74+ color = "#000061"
75+ />
76+ ) }
6377 </ div >
6478 ) ;
6579}
6680
67- export default ListView ;
81+ export default ListView ;
0 commit comments