From c48023ace4d94c9e20adffc39e6a2f5564fe0311 Mon Sep 17 00:00:00 2001 From: Zeeshaun Date: Wed, 6 May 2026 18:31:27 +0000 Subject: [PATCH] Updating --- baseball/src/app/api/games/[id]/route.ts | 7 +- baseball/src/app/api/games/route.ts | 7 +- baseball/src/components/GameHistoryClient.tsx | 99 +++++++++++---- baseball/src/components/GameScoringClient.tsx | 99 +++++++++++---- baseball/src/components/PlayerForm.tsx | 77 +++++++++--- baseball/src/components/RosterClient.tsx | 44 ++++--- baseball/src/lib/baseball-stats.ts | 117 ++++++++++++++++++ baseball/src/lib/types.ts | 12 +- baseball/src/lib/validators.ts | 14 ++- baseball/src/models/Game.ts | 13 +- baseball/src/models/Player.ts | 12 +- 11 files changed, 404 insertions(+), 97 deletions(-) create mode 100644 baseball/src/lib/baseball-stats.ts diff --git a/baseball/src/app/api/games/[id]/route.ts b/baseball/src/app/api/games/[id]/route.ts index c24a424..a9c2c6e 100644 --- a/baseball/src/app/api/games/[id]/route.ts +++ b/baseball/src/app/api/games/[id]/route.ts @@ -18,7 +18,12 @@ const statFields = [ "runsBattedIn", "walks", "strikeouts", - "stolenBases" + "stolenBases", + "inningsPitchedOuts", + "earnedRunsAllowed", + "hitsAllowed", + "walksAllowed", + "strikeoutsPitched" ] as const; export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) { diff --git a/baseball/src/app/api/games/route.ts b/baseball/src/app/api/games/route.ts index 2672016..090971c 100644 --- a/baseball/src/app/api/games/route.ts +++ b/baseball/src/app/api/games/route.ts @@ -21,7 +21,12 @@ const statFields = [ "runsBattedIn", "walks", "strikeouts", - "stolenBases" + "stolenBases", + "inningsPitchedOuts", + "earnedRunsAllowed", + "hitsAllowed", + "walksAllowed", + "strikeoutsPitched" ] as const; export async function GET(request: Request) { diff --git a/baseball/src/components/GameHistoryClient.tsx b/baseball/src/components/GameHistoryClient.tsx index c79a880..14ee82e 100644 --- a/baseball/src/components/GameHistoryClient.tsx +++ b/baseball/src/components/GameHistoryClient.tsx @@ -10,11 +10,11 @@ import { Alert } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; +import { getBattingSummary, getPitchingSummary, hasBattingStats, hasPitchingStats } from "@/lib/baseball-stats"; import { fetchJson } from "@/lib/client"; import type { GameRecord } from "@/lib/types"; -const statFields = [ - ["pitchCount", "Pitches"], +const battingFields = [ ["atBats", "AB"], ["runs", "R"], ["hits", "H"], @@ -27,6 +27,15 @@ const statFields = [ ["stolenBases", "SB"] ] as const; +const pitchingFields = [ + ["pitchCount", "Pitches"], + ["inningsPitchedOuts", "IP Outs"], + ["earnedRunsAllowed", "ER"], + ["hitsAllowed", "H Allowed"], + ["walksAllowed", "BB Allowed"], + ["strikeoutsPitched", "Pitching K"] +] as const; + export function GameHistoryClient() { const [gameDate, setGameDate] = useState(""); const [games, setGames] = useState([]); @@ -165,31 +174,67 @@ export function GameHistoryClient() { ) : null} -
- - - - - {statFields.map(([, label]) => ( - - ))} - - - - {game.playerStats.map((playerStat) => ( - - - {statFields.map(([field, label]) => ( - - ))} - - ))} - -
Player - {label} -
{playerStat.playerName} - {playerStat[field] ?? "-"} -
+
+ {game.playerStats.map((playerStat) => ( +
+
+

{playerStat.playerName}

+

Saved stat line

+
+
+
+

+ Hitting Summary +

+ {hasBattingStats(playerStat) ? ( +
+ {getBattingSummary(playerStat).map(([label, value]) => ( +
+ {label}{" "} + {value ?? "-"} +
+ ))} +
+ ) : ( +

No batting stats recorded.

+ )} +
+ {battingFields.map(([field, label]) => ( +
+ {label}{" "} + {playerStat[field] ?? "-"} +
+ ))} +
+
+
+

+ Pitching Summary +

+ {hasPitchingStats(playerStat) ? ( +
+ {getPitchingSummary(playerStat).map(([label, value]) => ( +
+ {label}{" "} + {value ?? "-"} +
+ ))} +
+ ) : ( +

No pitching stats recorded.

+ )} +
+ {pitchingFields.map(([field, label]) => ( +
+ {label}{" "} + {playerStat[field] ?? "-"} +
+ ))} +
+
+
+
+ ))}
diff --git a/baseball/src/components/GameScoringClient.tsx b/baseball/src/components/GameScoringClient.tsx index 7e623b2..37df8c7 100644 --- a/baseball/src/components/GameScoringClient.tsx +++ b/baseball/src/components/GameScoringClient.tsx @@ -12,8 +12,7 @@ import { Textarea } from "@/components/ui/textarea"; import { fetchJson } from "@/lib/client"; import type { GamePlayerStatsInput, GameRecord, LineupRecord } from "@/lib/types"; -const statFields = [ - ["pitchCount", "Pitches"], +const battingFields = [ ["atBats", "AB"], ["runs", "R"], ["hits", "H"], @@ -26,6 +25,15 @@ const statFields = [ ["stolenBases", "SB"] ] as const; +const pitchingFields = [ + ["pitchCount", "Pitches"], + ["inningsPitchedOuts", "IP Outs"], + ["earnedRunsAllowed", "ER"], + ["hitsAllowed", "H Allowed"], + ["walksAllowed", "BB Allowed"], + ["strikeoutsPitched", "Pitching K"] +] as const; + function pickDefaultLineupId(gameDate: string, lineups: LineupRecord[]) { const exactDate = lineups.find((lineup) => lineup.gameDate === gameDate); return exactDate?._id ?? lineups[0]?._id ?? ""; @@ -196,16 +204,6 @@ export function GameScoringClient() { Opponent setOpponent(event.target.value)} placeholder="Optional" /> -
- - -