From 4be18e69c2c9915bad6caddadc50e4122a5ce7f1 Mon Sep 17 00:00:00 2001 From: Rajkumar Date: Sat, 26 Sep 2026 00:52:53 +0530 Subject: [PATCH] (fixed) leaderboard failing in less than three users --- apps/frontend/src/components/Badge.tsx | 4 ++-- apps/frontend/src/screens/LiveQuiz.tsx | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/apps/frontend/src/components/Badge.tsx b/apps/frontend/src/components/Badge.tsx index 5cfaa0d..778dcde 100644 --- a/apps/frontend/src/components/Badge.tsx +++ b/apps/frontend/src/components/Badge.tsx @@ -16,7 +16,7 @@ function Badge() { {/* Left */}

- Version-v1 + Version-v2

{/* Divider */} @@ -24,7 +24,7 @@ function Badge() { {/* Right */}

- v2 - In Progress + v3 - In Progress

diff --git a/apps/frontend/src/screens/LiveQuiz.tsx b/apps/frontend/src/screens/LiveQuiz.tsx index c66a7ea..689432c 100644 --- a/apps/frontend/src/screens/LiveQuiz.tsx +++ b/apps/frontend/src/screens/LiveQuiz.tsx @@ -56,11 +56,15 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) { const [qIndex, setQIndex] = useState(0); - const topThree = leaderboard.slice(0, 3); + const sortedLeaderboard = [...leaderboard].sort((a, b) => (b.score ?? 0) - (a.score ?? 0)); - const three = [topThree[1], topThree[0], topThree[2]]; + const podium = [ + { rank: 1, player: sortedLeaderboard[0] }, + { rank: 2, player: sortedLeaderboard[1] }, + { rank: 3, player: sortedLeaderboard[2] }, + ].filter((entry): entry is { rank: number; player: any } => Boolean(entry.player)); - const others = leaderboard.slice(3); + const others = sortedLeaderboard.slice(3); // if participant is missing, kick them out @@ -607,15 +611,14 @@ function LiveQuiz({ isOrganizer = false }: LiveQuizProps) {
{/* top three performers */} -
- {three.map((player, idx) => { - const isFirst = idx === 1; - const rank = isFirst ? 1 : idx === 0 ? 2 : 3; +
+ {podium.map(({ rank, player }) => { + const isFirst = rank === 1; return (
- Rank: {rank} + Rank: {rank}
- + {player.score} pts