Skip to content

Commit

Permalink
use enum
Browse files Browse the repository at this point in the history
  • Loading branch information
GilMM27 committed Oct 31, 2024
1 parent 4a366cc commit 9015760
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
31 changes: 17 additions & 14 deletions src/app/scoreboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -97,22 +98,24 @@ export default function ScoreboardPage() {
{scores?.map((team) => (
<tr
key={team.teamId}
className="border-b border-gray-700/50 transition-colors hover:bg-gray-800/30"
className="border-b border-gray-700 transition-colors hover:bg-gray-800/30"
>
<td className="p-4 font-medium">{team.teamName}</td>
{[1, 2, 3].map((roundId) => (
<React.Fragment key={roundId}>
<td className="p-4 text-center">
{team.rounds[roundId]?.challengeA}
</td>
<td className="p-4 text-center">
{team.rounds[roundId]?.challengeB}
</td>
<td className="p-4 text-center">
{team.rounds[roundId]?.challengeC}
</td>
</React.Fragment>
))}
{Object.values(Round)
.filter((value): value is number => typeof value === "number") // Filter only numeric values
.map((roundId) => (
<React.Fragment key={roundId}>
<td className="p-4 text-center">
{team.rounds[roundId]?.challengeA ?? "-"}
</td>
<td className="p-4 text-center">
{team.rounds[roundId]?.challengeB ?? "-"}
</td>
<td className="p-4 text-center">
{team.rounds[roundId]?.challengeC ?? "-"}
</td>
</React.Fragment>
))}
<td className="p-4 text-center font-semibold">{team.total}</td>
</tr>
))}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/round.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Round {
A = 1,
B = 2,
C = 3,
}
17 changes: 10 additions & 7 deletions src/server/api/routers/scoreboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9015760

Please sign in to comment.