Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions apps/frontend/src/screens/LiveQuiz.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
55 changes: 23 additions & 32 deletions apps/frontend/src/screens/LiveQuiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
const [sendFailed, setSendFailed] = useState(false);
const isConnected = connectionState === 'connected';
const [gameState, setGameState] = useState<GameState>('WAITING');
const [participants, setParticipants] = useState<any[]>([]);

Check failure on line 61 in apps/frontend/src/screens/LiveQuiz.tsx

View workflow job for this annotation

GitHub Actions / Lint & type-check

Unexpected any. Specify a different type
const [currentQuestion, setCurrentQuestion] = useState<any>(null);

Check failure on line 62 in apps/frontend/src/screens/LiveQuiz.tsx

View workflow job for this annotation

GitHub Actions / Lint & type-check

Unexpected any. Specify a different type
const [timeLeft, setTimeLeft] = useState(0);
const [correctAnswers, setCorrectAnswers] = useState<string[]>([]);
const [leaderboard, setLeaderboard] = useState<any[]>([]);

Check failure on line 65 in apps/frontend/src/screens/LiveQuiz.tsx

View workflow job for this annotation

GitHub Actions / Lint & type-check

Unexpected any. Specify a different type

const [joinCode, setJoinCode] = useState('');
// Set by the server on join: the host opened this lobby with live video.
Expand Down Expand Up @@ -135,7 +135,7 @@
{ rank: 2, player: sortedLeaderboard[1], order: 'order-2 sm:order-1' },
{ rank: 1, player: sortedLeaderboard[0], order: 'order-1 sm:order-2' },
{ rank: 3, player: sortedLeaderboard[2], order: 'order-3 sm:order-3' },
].filter((entry): entry is { rank: number; player: any; order: string } => Boolean(entry.player));

Check failure on line 138 in apps/frontend/src/screens/LiveQuiz.tsx

View workflow job for this annotation

GitHub Actions / Lint & type-check

Unexpected any. Specify a different type

// Everyone past the podium, capped: a 500-player session rendered the whole
// board, so the end of a quiz was a page of names nobody reads.
Expand Down Expand Up @@ -425,7 +425,7 @@
}
};

}, [sessionId, isOrganizer]);

Check warning on line 428 in apps/frontend/src/screens/LiveQuiz.tsx

View workflow job for this annotation

GitHub Actions / Lint & type-check

React Hook useEffect has missing dependencies: 'navigate', 'participantId', 'token', and 'user?.id'. Either include them or remove the dependency array


// `ws?.send` on a closed socket does nothing and throws nothing, so every
Expand Down Expand Up @@ -1010,6 +1010,12 @@
</div>
{/* Rest of the performers till top-30 */}
<div className="space-y-5">
{hiddenCount > 0 && (
<p className="text-center text-zinc-500 text-sm sm:text-base font-secondary tracking-wider py-2">
Showing the top {FINAL_LIMIT} of {sortedLeaderboard.length} players
</p>
)}

{others.map((player, idx) => (
<div
key={player.id}
Expand Down Expand Up @@ -1043,44 +1049,29 @@
standing rather than ending the quiz on other people's
names. */}
{showMyRank && (
<>
{hiddenCount > 0 && (
<p className="text-center text-zinc-500 text-sm sm:text-base font-secondary tracking-wider py-2">
+ {hiddenCount} more {hiddenCount === 1 ? 'player' : 'players'}
</p>
)}

<div className="flex justify-between items-center px-4 sm:py-5 py-3 rounded-2xl border-2 border-pink-500/60 bg-pink-600/15">
<div className="flex items-center gap-3 sm:gap-4">
<span className="text-lg sm:text-2xl font-black text-pink-400 tracking-tighter">
#{myRank}
</span>

<div className={`sm:w-12 sm:h-12 h-10 w-10 rounded-xl bg-linear-to-br ${getAvatarColor(me!.id)} p-0.5 shadow overflow-hidden`}>
<img
src={getAvatar(me!.id)}
alt={me!.username}
className="w-full h-full object-cover"
/>
</div>
<div className="flex justify-between items-center px-4 sm:py-5 py-3 rounded-2xl border-2 border-pink-500/60 bg-pink-600/15">
<div className="flex items-center gap-3 sm:gap-4">
<span className="text-lg sm:text-2xl font-black text-pink-400 tracking-tighter">
#{myRank}
</span>

<span className="text-md sm:text-xl font-secondary font-extrabold tracking-wider text-pink-400">
You
</span>
<div className={`sm:w-12 sm:h-12 h-10 w-10 rounded-xl bg-linear-to-br ${getAvatarColor(me!.id)} p-0.5 shadow overflow-hidden`}>
<img
src={getAvatar(me!.id)}
alt={me!.username}
className="w-full h-full object-cover"
/>
</div>

<span className="text-md sm:text-2xl font-special tracking-wider text-pink-400">
{me!.score} pts
<span className="text-md sm:text-xl font-secondary font-extrabold tracking-wider text-pink-400">
You
</span>
</div>
</>
)}

{/* Nothing pinned below, so say the list was cut. */}
{!showMyRank && hiddenCount > 0 && (
<p className="text-center text-zinc-500 text-sm sm:text-base font-secondary tracking-wider py-2">
+ {hiddenCount} more {hiddenCount === 1 ? 'player' : 'players'}
</p>
<span className="text-md sm:text-2xl font-special tracking-wider text-pink-400">
{me!.score} pts
</span>
</div>
)}
</div>

Expand Down
Loading