From aa121bbcf34a3e41a548e0db1560a50a90021109 Mon Sep 17 00:00:00 2001 From: Ross Andrews Date: Thu, 28 May 2026 22:36:39 -0500 Subject: [PATCH] Add per-round edit button to scoresheet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A ✎ button next to each round label opens the score entry form pre-populated with that round's scores. Submitting replaces the round in place instead of appending a new one. Co-Authored-By: Claude Sonnet 4.6 --- src/App.tsx | 16 +++++++++++++--- src/pages/EnterScores.tsx | 7 +++++-- src/pages/ScoreSheet.module.css | 14 ++++++++++++++ src/pages/ScoreSheet.tsx | 8 ++++++-- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 678dc54..b7de2d5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -24,6 +24,7 @@ export default function App() { const [game, setGame] = useState(loadGame) const [page, setPage] = useState(() => (game ? 'scoresheet' : 'title')) const [previousPlayers, setPreviousPlayers] = useState(undefined) + const [editingRound, setEditingRound] = useState(null) function handleNewGame() { setPreviousPlayers(game?.players) @@ -39,15 +40,24 @@ export default function App() { setPage('scoresheet') } + function handleEditRound(i: number) { + setEditingRound(i) + setPage('enterscores') + } + function handleSubmitScores(scores: number[]) { - const updated: GameState = { ...game!, rounds: [...game!.rounds, scores] } + const rounds = editingRound !== null + ? game!.rounds.map((r, i) => (i === editingRound ? scores : r)) + : [...game!.rounds, scores] + const updated: GameState = { ...game!, rounds } saveGame(updated) setGame(updated) + setEditingRound(null) setPage('scoresheet') } if (page === 'title') return if (page === 'setup') return - if (page === 'scoresheet') return setPage('enterscores')} onNewGame={handleNewGame} /> - if (page === 'enterscores') return + if (page === 'scoresheet') return setPage('enterscores')} onNewGame={handleNewGame} onEditRound={handleEditRound} /> + if (page === 'enterscores') return } diff --git a/src/pages/EnterScores.tsx b/src/pages/EnterScores.tsx index 8463dac..98980c9 100644 --- a/src/pages/EnterScores.tsx +++ b/src/pages/EnterScores.tsx @@ -8,10 +8,13 @@ import styles from './EnterScores.module.css' interface Props { game: GameState onSubmit: (scores: number[]) => void + initialValues?: number[] } -export default function EnterScores({ game, onSubmit }: Props) { - const [values, setValues] = useState(() => game.players.map(() => '')) +export default function EnterScores({ game, onSubmit, initialValues }: Props) { + const [values, setValues] = useState(() => + game.players.map((_, i) => initialValues ? String(initialValues[i]) : '') + ) function updateValue(i: number, v: string) { setValues(vs => vs.map((val, idx) => (idx === i ? v : val))) diff --git a/src/pages/ScoreSheet.module.css b/src/pages/ScoreSheet.module.css index 70c1b36..87c1ea0 100644 --- a/src/pages/ScoreSheet.module.css +++ b/src/pages/ScoreSheet.module.css @@ -28,6 +28,20 @@ font-size: 0.75rem; color: #666; white-space: nowrap; + display: flex; + align-items: center; + gap: 0.3rem; +} + +.editBtn { + background: none; + border: none; + padding: 0; + min-height: unset; + font-size: 0.85rem; + color: #aaa; + line-height: 1; + box-shadow: none; } .scoreCell { diff --git a/src/pages/ScoreSheet.tsx b/src/pages/ScoreSheet.tsx index 69aaf4e..b0e4cf0 100644 --- a/src/pages/ScoreSheet.tsx +++ b/src/pages/ScoreSheet.tsx @@ -9,9 +9,10 @@ interface Props { game: GameState onScoreRound: () => void onNewGame: () => void + onEditRound: (i: number) => void } -export default function ScoreSheet({ game, onScoreRound, onNewGame }: Props) { +export default function ScoreSheet({ game, onScoreRound, onNewGame, onEditRound }: Props) { const [confirmingNewGame, setConfirmingNewGame] = useState(false) const totals = computeRunningTotals(game.rounds) @@ -62,7 +63,10 @@ export default function ScoreSheet({ game, onScoreRound, onNewGame }: Props) { {game.rounds.map((roundScores, i) => ( -
Round {i + 1}
+
+ + Round {i + 1} +
{roundScores.map((score, j) => (
{score}
))}