@@ -8,9 +8,12 @@ import {
88import { Button } from "@/components/ui/button" ;
99import { Input } from "@/components/ui/input" ;
1010import { Star , Pencil } from "lucide-react" ;
11- import { useState , useEffect } from "react" ;
11+ import { useState , useEffect } from "react" ;
1212import TimetableCardKebabMenu from "./TimetableCardKebabMenu" ;
13- import { useUpdateTimetableMutation , useGetTimetableQuery } from "@/api/timetableApiSlice" ;
13+ import {
14+ useUpdateTimetableMutation ,
15+ useGetTimetableQuery ,
16+ } from "@/api/timetableApiSlice" ;
1417import { Link } from "react-router-dom" ;
1518import { TimetableModel } from "@/models/models" ;
1619
@@ -34,12 +37,10 @@ const TimetableCard = ({
3437 title,
3538 lastEditedDate,
3639 owner,
37- favorite
40+ favorite,
3841} : TimetableCardProps ) => {
3942 const [ updateTimetable ] = useUpdateTimetableMutation ( ) ;
4043
41-
42-
4344 const lastEditedDateArray = lastEditedDate
4445 . toISOString ( )
4546 . split ( "T" ) [ 0 ]
@@ -76,25 +77,25 @@ const TimetableCard = ({
7677 }
7778 } , [ data ] ) ;
7879
79- const handleFavourite = async ( ) => {
80- try {
81- await updateTimetable ( {
82- id : timetableId ,
83- favorite : ! toggled ,
84- } ) . unwrap ( ) ;
85- refetch ( ) ;
86- console . log ( "Favourite success!" ) ;
87- setToggled ( ! toggled ) ;
88- console . log ( ! toggled ) ;
89- handleReload ( ) ;
90- } catch ( error ) {
91- console . error ( "Failed to favourite timetable:" , error ) ;
92- }
93- } ;
94-
95- const handleReload = ( ) => {
96- window . location . reload ( ) ; // Reloads the page
97- } ;
80+ const handleFavourite = async ( ) => {
81+ try {
82+ await updateTimetable ( {
83+ id : timetableId ,
84+ favorite : ! toggled ,
85+ } ) . unwrap ( ) ;
86+ refetch ( ) ;
87+ console . log ( "Favourite success!" ) ;
88+ setToggled ( ! toggled ) ;
89+ console . log ( ! toggled ) ;
90+ handleReload ( ) ;
91+ } catch ( error ) {
92+ console . error ( "Failed to favourite timetable:" , error ) ;
93+ }
94+ } ;
95+
96+ const handleReload = ( ) => {
97+ window . location . reload ( ) ; // Reloads the page
98+ } ;
9899
99100 return (
100101 < Card className = "w-full" >
@@ -106,7 +107,6 @@ const TimetableCard = ({
106107 />
107108 </ Link >
108109 < div className = "flex justify-between items-center" >
109-
110110 < CardTitle >
111111 < Input
112112 disabled = { ! isEditingTitle }
@@ -120,9 +120,14 @@ const TimetableCard = ({
120120 />
121121 </ CardTitle >
122122
123- < Star className = { `w-6 h-6 transition-colors ${
124- toggled ? "fill-none text-gray-500" : "fill-yellow-500 text-yellow-500"
125- } `} onClick = { ( ) => handleFavourite ( ) } />
123+ < Star
124+ className = { `w-6 h-6 transition-colors ${
125+ toggled
126+ ? "fill-none text-gray-500"
127+ : "fill-yellow-500 text-yellow-500"
128+ } `}
129+ onClick = { ( ) => handleFavourite ( ) }
130+ />
126131 < div className = "flex justify-between" >
127132 { ! isEditingTitle && (
128133 < >
0 commit comments