Skip to content

Commit ca299f5

Browse files
committed
animation to star
1 parent 927e964 commit ca299f5

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

src/components/Table/index.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ const Table = () => {
115115
const [showPatterns, setShowPatterns] = useState(
116116
JSON.parse(localStorage.getItem('showPatterns')) || new Array(1).fill(true),
117117
);
118-
119118
const savedImportant = JSON.parse(localStorage.getItem('importantProblems'));
120119
const [important, setImportant] = useState(
121120
savedImportant && savedImportant.length === questions.length
122121
? savedImportant
123122
: new Array(questions.length).fill(false),
124123
);
124+
const [starAnimation, setStarAnimation] = useState({});
125125

126126
// Returns an array of question objects that are starred
127127
const getStarredQuestions = () => {
@@ -508,46 +508,47 @@ const Table = () => {
508508
const id = Number(row?.original?.id);
509509
if (Number.isNaN(id)) return '❌';
510510

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+
511533
const handleKeyPress = e => {
512534
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();
527536
}
528537
};
529538

530539
return (
531540
<span
532541
role="button"
533542
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',
550547
}}
548+
className={
549+
important[id] && starAnimation[id] ? 'star-animate' : ''
550+
}
551+
onClick={handleToggle}
551552
onKeyDown={handleKeyPress}
552553
aria-label="Mark as important for revision"
553554
data-tip="Mark as important for revision"

src/components/Table/styles.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,25 @@ body.dark-mode .modal-content {
123123
text-wrap: nowrap;
124124
}
125125
}
126+
127+
.star-animate {
128+
animation: pop-star 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
129+
}
130+
131+
@keyframes pop-star {
132+
0% {
133+
transform: scale(1) rotate(0deg);
134+
color: #ffd700;
135+
filter: drop-shadow(0 0 0 #ffd700);
136+
}
137+
60% {
138+
transform: scale(1.5) rotate(-15deg);
139+
color: #ffd700;
140+
filter: drop-shadow(0 0 8px #ffd700);
141+
}
142+
100% {
143+
transform: scale(1) rotate(0deg);
144+
color: #ffd700;
145+
filter: drop-shadow(0 0 0 #ffd700);
146+
}
147+
}

0 commit comments

Comments
 (0)