Felix Zieger
commited on
Commit
·
ad17252
1
Parent(s):
483e9c5
medals
Browse files
src/components/HighScoreBoard.tsx
CHANGED
@@ -38,6 +38,19 @@ interface HighScoreBoardProps {
|
|
38 |
|
39 |
const ITEMS_PER_PAGE = 10;
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
export const HighScoreBoard = ({
|
42 |
currentScore,
|
43 |
avgWordsPerRound,
|
@@ -176,14 +189,21 @@ export const HighScoreBoard = ({
|
|
176 |
</TableRow>
|
177 |
</TableHeader>
|
178 |
<TableBody>
|
179 |
-
{paginatedScores?.map((score, index) =>
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
<
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
{!paginatedScores?.length && (
|
188 |
<TableRow>
|
189 |
<TableCell colSpan={4} className="text-center">
|
@@ -232,4 +252,4 @@ export const HighScoreBoard = ({
|
|
232 |
</div>
|
233 |
</div>
|
234 |
);
|
235 |
-
};
|
|
|
38 |
|
39 |
const ITEMS_PER_PAGE = 10;
|
40 |
|
41 |
+
const getRankMedal = (rank: number) => {
|
42 |
+
switch (rank) {
|
43 |
+
case 1:
|
44 |
+
return "🥇";
|
45 |
+
case 2:
|
46 |
+
return "🥈";
|
47 |
+
case 3:
|
48 |
+
return "🥉";
|
49 |
+
default:
|
50 |
+
return null;
|
51 |
+
}
|
52 |
+
};
|
53 |
+
|
54 |
export const HighScoreBoard = ({
|
55 |
currentScore,
|
56 |
avgWordsPerRound,
|
|
|
189 |
</TableRow>
|
190 |
</TableHeader>
|
191 |
<TableBody>
|
192 |
+
{paginatedScores?.map((score, index) => {
|
193 |
+
const absoluteRank = startIndex + index + 1;
|
194 |
+
const medal = getRankMedal(absoluteRank);
|
195 |
+
return (
|
196 |
+
<TableRow key={score.id}>
|
197 |
+
<TableCell>
|
198 |
+
{absoluteRank}
|
199 |
+
{medal && <span className="ml-2">{medal}</span>}
|
200 |
+
</TableCell>
|
201 |
+
<TableCell>{score.player_name}</TableCell>
|
202 |
+
<TableCell>{score.score}</TableCell>
|
203 |
+
<TableCell>{score.avg_words_per_round.toFixed(1)}</TableCell>
|
204 |
+
</TableRow>
|
205 |
+
);
|
206 |
+
})}
|
207 |
{!paginatedScores?.length && (
|
208 |
<TableRow>
|
209 |
<TableCell colSpan={4} className="text-center">
|
|
|
252 |
</div>
|
253 |
</div>
|
254 |
);
|
255 |
+
};
|