From bfc12afe7ff2f283d2ace36b21ba1df3e818877a Mon Sep 17 00:00:00 2001 From: spikedeeev Date: Wed, 18 Nov 2026 16:57:22 +0200 Subject: [PATCH] feat: show current player rank on final leaderboard --- apps/frontend/src/screens/LiveQuiz.test.tsx | 35 +++++++++++++ apps/frontend/src/screens/LiveQuiz.tsx | 55 +++++++++------------ 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/apps/frontend/src/screens/LiveQuiz.test.tsx b/apps/frontend/src/screens/LiveQuiz.test.tsx index bcab9f8..84da45d 100644 --- a/apps/frontend/src/screens/LiveQuiz.test.tsx +++ b/apps/frontend/src/screens/LiveQuiz.test.tsx @@ -237,3 +237,38 @@ describe('LiveQuiz host start countdown', () => { expect(sentOfType('quiz:next-question')).toHaveLength(0); }); }); + +describe('LiveQuiz final leaderboard', () => { + function rankedPlayers(count: number) { + return Array.from({ length: count }, (_, index) => ({ + id: `participant-${index + 1}`, + username: `Player ${index + 1}`, + score: count - index, + totalTimeMs: index, + })); + } + + it('shows the full-list rank and score for a participant outside the top 30', async () => { + localStorage.setItem('rexial:participant:session-1', 'participant-35'); + renderLive('/live/session-1', false); + await firstJoinMessage(); + deliver('quiz:leaderboard', { leaderboard: rankedPlayers(35) }); + deliver('quiz:ended', {}); + + expect(await screen.findByText('Showing the top 30 of 35 players')).toBeInTheDocument(); + expect(screen.getByText('#35')).toBeInTheDocument(); + expect(screen.getByText('You')).toBeInTheDocument(); + expect(screen.getByText('1 pts')).toBeInTheDocument(); + }); + + it('highlights a participant whose row is already in the visible top 30', async () => { + localStorage.setItem('rexial:participant:session-1', 'participant-17'); + renderLive('/live/session-1', false); + await firstJoinMessage(); + deliver('quiz:leaderboard', { leaderboard: rankedPlayers(35) }); + deliver('quiz:ended', {}); + + const player = await screen.findByText('Player 17'); + expect(player.closest('div[class*="ring-2"]')).not.toBeNull(); + }); +}); diff --git a/apps/frontend/src/screens/LiveQuiz.tsx b/apps/frontend/src/screens/LiveQuiz.tsx index 5886eaa..5abde77 100644 --- a/apps/frontend/src/screens/LiveQuiz.tsx +++ b/apps/frontend/src/screens/LiveQuiz.tsx @@ -1010,6 +1010,12 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) { {/* Rest of the performers till top-30 */}
+ {hiddenCount > 0 && ( +

+ Showing the top {FINAL_LIMIT} of {sortedLeaderboard.length} players +

+ )} + {others.map((player, idx) => (
- {hiddenCount > 0 && ( -

- + {hiddenCount} more {hiddenCount === 1 ? 'player' : 'players'} -

- )} - -
-
- - #{myRank} - - -
- {me!.username} -
+
+
+ + #{myRank} + - - You - +
+ {me!.username}
- - {me!.score} pts + + You
- - )} - {/* Nothing pinned below, so say the list was cut. */} - {!showMyRank && hiddenCount > 0 && ( -

- + {hiddenCount} more {hiddenCount === 1 ? 'player' : 'players'} -

+ + {me!.score} pts + +
)}