@@ -115,13 +115,13 @@ const Table = () => {
115
115
const [ showPatterns , setShowPatterns ] = useState (
116
116
JSON . parse ( localStorage . getItem ( 'showPatterns' ) ) || new Array ( 1 ) . fill ( true ) ,
117
117
) ;
118
-
119
118
const savedImportant = JSON . parse ( localStorage . getItem ( 'importantProblems' ) ) ;
120
119
const [ important , setImportant ] = useState (
121
120
savedImportant && savedImportant . length === questions . length
122
121
? savedImportant
123
122
: new Array ( questions . length ) . fill ( false ) ,
124
123
) ;
124
+ const [ starAnimation , setStarAnimation ] = useState ( { } ) ;
125
125
126
126
// Returns an array of question objects that are starred
127
127
const getStarredQuestions = ( ) => {
@@ -508,46 +508,47 @@ const Table = () => {
508
508
const id = Number ( row ?. original ?. id ) ;
509
509
if ( Number . isNaN ( id ) ) return '❌' ;
510
510
511
+ const handleToggle = ( ) => {
512
+ const updatedImportant = [ ...important ] ;
513
+ updatedImportant [ id ] = ! updatedImportant [ id ] ;
514
+ setImportant ( updatedImportant ) ;
515
+ toast (
516
+ updatedImportant [ id ]
517
+ ? 'Marked as Important'
518
+ : 'Removed from Important' ,
519
+ {
520
+ type : updatedImportant [ id ] ? 'success' : 'info' ,
521
+ autoClose : 1200 ,
522
+ hideProgressBar : true ,
523
+ position : 'bottom-center' ,
524
+ } ,
525
+ ) ;
526
+ // Trigger animation
527
+ setStarAnimation ( prev => ( { ...prev , [ id ] : true } ) ) ;
528
+ setTimeout ( ( ) => {
529
+ setStarAnimation ( prev => ( { ...prev , [ id ] : false } ) ) ;
530
+ } , 400 ) ;
531
+ } ;
532
+
511
533
const handleKeyPress = e => {
512
534
if ( e . key === 'Enter' || e . key === ' ' ) {
513
- const updatedImportant = [ ...important ] ;
514
- updatedImportant [ id ] = ! updatedImportant [ id ] ;
515
- setImportant ( updatedImportant ) ;
516
- toast (
517
- updatedImportant [ id ]
518
- ? 'Marked as Important'
519
- : 'Removed from Important' ,
520
- {
521
- type : updatedImportant [ id ] ? 'success' : 'info' ,
522
- autoClose : 1200 ,
523
- hideProgressBar : true ,
524
- position : 'bottom-center' ,
525
- } ,
526
- ) ;
535
+ handleToggle ( ) ;
527
536
}
528
537
} ;
529
538
530
539
return (
531
540
< span
532
541
role = "button"
533
542
tabIndex = { 0 }
534
- style = { { cursor : 'pointer' , fontSize : '1.2em' } }
535
- onClick = { ( ) => {
536
- const updatedImportant = [ ...important ] ;
537
- updatedImportant [ id ] = ! updatedImportant [ id ] ;
538
- setImportant ( updatedImportant ) ;
539
- toast (
540
- updatedImportant [ id ]
541
- ? 'Marked as Important'
542
- : 'Removed from Important' ,
543
- {
544
- type : updatedImportant [ id ] ? 'success' : 'info' ,
545
- autoClose : 1200 ,
546
- hideProgressBar : true ,
547
- position : 'bottom-center' ,
548
- } ,
549
- ) ;
543
+ style = { {
544
+ cursor : 'pointer' ,
545
+ fontSize : '1.2em' ,
546
+ transition : 'color 0.2s' ,
550
547
} }
548
+ className = {
549
+ important [ id ] && starAnimation [ id ] ? 'star-animate' : ''
550
+ }
551
+ onClick = { handleToggle }
551
552
onKeyDown = { handleKeyPress }
552
553
aria-label = "Mark as important for revision"
553
554
data-tip = "Mark as important for revision"
0 commit comments