Skip to content

Commit a107205

Browse files
committed
Create ScoreButton component
1 parent 69cd002 commit a107205

3 files changed

Lines changed: 32 additions & 43 deletions

File tree

cue-client/src/components/study-stack.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useNotification } from '../hooks/notification-hook';
99
import { Ban, Check, Frown, Meh, Smile } from 'lucide-react';
1010
import { Button } from './ui/button';
1111
import ScoreBoard from './study/score-board';
12+
import ScoreButton from './study/score-button';
1213

1314
interface ScoredCard extends Card {
1415
score: number;
@@ -156,31 +157,10 @@ function CardFlipper({
156157
readOnly={!editing}
157158
/>
158159
)}
159-
<div className="scores" style={{ display: !editing && showScores ? 'flex' : 'none' }}>
160-
<div
161-
onClick={(e) => {
162-
e.stopPropagation();
163-
updateScore(0);
164-
}}
165-
>
166-
<Frown size={16} />
167-
</div>
168-
<div
169-
onClick={(e) => {
170-
e.stopPropagation();
171-
updateScore(1);
172-
}}
173-
>
174-
<Meh size={16} />
175-
</div>
176-
<div
177-
onClick={(e) => {
178-
e.stopPropagation();
179-
updateScore(2);
180-
}}
181-
>
182-
<Smile size={16} />
183-
</div>
160+
<div className="flex-row gap-2" style={{ display: !editing && showScores ? 'flex' : 'none' }}>
161+
<ScoreButton score={0} updateScore={updateScore} />
162+
<ScoreButton score={1} updateScore={updateScore} />
163+
<ScoreButton score={2} updateScore={updateScore} />
184164
</div>
185165
<div className="flex-row gap-2" style={{ display: editing ? 'flex' : 'none' }}>
186166
<Button
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Frown, LucideIcon, Meh, Smile } from 'lucide-react';
2+
3+
const iconByScore: Record<number, LucideIcon> = {
4+
0: Frown,
5+
1: Meh,
6+
2: Smile,
7+
};
8+
9+
export default function ScoreButton({
10+
score,
11+
updateScore,
12+
}: {
13+
score: number;
14+
updateScore: (score: number) => Promise<void>;
15+
}) {
16+
if (score < 0 || score > 2) return null;
17+
const Icon = iconByScore[score];
18+
return (
19+
<button
20+
onClick={() => updateScore(score)}
21+
aria-label={`Set score ${score}`}
22+
className="text-white bg-black w-12 h-12 rounded-full flex items-center justify-center cursor-pointer transition-all duration-150 hover:bg-gray-800 hover:scale-105 active:scale-95"
23+
>
24+
<Icon size={16} />
25+
</button>
26+
);
27+
}

cue-client/src/index.css

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,6 @@ main #content {
194194
background-color: var(--green);
195195
}
196196

197-
.scores {
198-
flex-direction: row;
199-
gap: 0.5rem;
200-
}
201-
.scores div {
202-
color: white;
203-
background-color: black;
204-
border-radius: 3rem;
205-
width: 3rem;
206-
height: 3rem;
207-
208-
display: flex;
209-
justify-content: center;
210-
align-items: center;
211-
212-
cursor: pointer;
213-
}
214-
215197
@theme inline {
216198
--radius-sm: calc(var(--radius) - 4px);
217199
--radius-md: calc(var(--radius) - 2px);

0 commit comments

Comments
 (0)