diff --git a/src/app/scoreboard/page.tsx b/src/app/scoreboard/page.tsx index 2fd9165..cef3390 100644 --- a/src/app/scoreboard/page.tsx +++ b/src/app/scoreboard/page.tsx @@ -6,6 +6,7 @@ import Header from "../_components/header"; import Title from "../_components/title"; import TwitchEmbed from "../_components/TwitchEmbed"; // Optional: Move TwitchEmbed to a separate file import { api } from "~/trpc/react"; +import { Round } from "../../lib/round"; export default function ScoreboardPage() { const { data: scores, isLoading } = api.scoreboard.getScoreboard.useQuery(); @@ -97,22 +98,24 @@ export default function ScoreboardPage() { {scores?.map((team) => ( {team.teamName} - {[1, 2, 3].map((roundId) => ( - - - {team.rounds[roundId]?.challengeA} - - - {team.rounds[roundId]?.challengeB} - - - {team.rounds[roundId]?.challengeC} - - - ))} + {Object.values(Round) + .filter((value): value is number => typeof value === "number") // Filter only numeric values + .map((roundId) => ( + + + {team.rounds[roundId]?.challengeA ?? "-"} + + + {team.rounds[roundId]?.challengeB ?? "-"} + + + {team.rounds[roundId]?.challengeC ?? "-"} + + + ))} {team.total} ))} diff --git a/src/lib/round.ts b/src/lib/round.ts new file mode 100644 index 0000000..c50559f --- /dev/null +++ b/src/lib/round.ts @@ -0,0 +1,5 @@ +export enum Round { + A = 1, + B = 2, + C = 3, +} diff --git a/src/server/api/routers/scoreboard.ts b/src/server/api/routers/scoreboard.ts index 2766fbb..faef404 100644 --- a/src/server/api/routers/scoreboard.ts +++ b/src/server/api/routers/scoreboard.ts @@ -22,6 +22,7 @@ type TeamScores = { // server/api/routers/scores.ts import { z } from "zod"; import { createTRPCRouter, publicProcedure } from "../trpc"; +import { Round } from "rbrgs/lib/round"; export const scoreboardRouter = createTRPCRouter({ getScoreboard: publicProcedure.query(async ({ ctx }) => { @@ -49,13 +50,15 @@ export const scoreboardRouter = createTRPCRouter({ total: 0, }; - // Initialize rounds data - [1, 2, 3].forEach((roundId) => { - scores.rounds[roundId] = { - challengeA: 0, - challengeB: 0, - challengeC: 0, - }; + // Initialize rounds data using the Round enum + Object.values(Round).forEach((roundId) => { + if (typeof roundId === "number") { + scores.rounds[roundId] = { + challengeA: 0, + challengeB: 0, + challengeC: 0, + }; + } }); // Fill in challenge scores