diff --git a/src/App.tsx b/src/App.tsx index 7d8f681..678dc54 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,8 +23,10 @@ function clearGame() { export default function App() { const [game, setGame] = useState(loadGame) const [page, setPage] = useState(() => (game ? 'scoresheet' : 'title')) + const [previousPlayers, setPreviousPlayers] = useState(undefined) function handleNewGame() { + setPreviousPlayers(game?.players) clearGame() setGame(null) setPage('setup') @@ -45,7 +47,7 @@ export default function App() { } if (page === 'title') return - if (page === 'setup') return + if (page === 'setup') return if (page === 'scoresheet') return setPage('enterscores')} onNewGame={handleNewGame} /> if (page === 'enterscores') return } diff --git a/src/pages/PlayerSetup.tsx b/src/pages/PlayerSetup.tsx index 256d6e5..a1550fe 100644 --- a/src/pages/PlayerSetup.tsx +++ b/src/pages/PlayerSetup.tsx @@ -5,14 +5,15 @@ import styles from './PlayerSetup.module.css' interface Props { onStart: (players: string[]) => void + initialNames?: string[] } function normalize(s: string) { return s.trim().replace(/\s+/g, ' ') } -export default function PlayerSetup({ onStart }: Props) { - const [names, setNames] = useState(['', '', '']) +export default function PlayerSetup({ onStart, initialNames }: Props) { + const [names, setNames] = useState(initialNames ?? ['', '', '']) function updateName(i: number, value: string) { setNames(n => n.map((v, idx) => (idx === i ? value : v))) diff --git a/src/pages/ScoreSheet.module.css b/src/pages/ScoreSheet.module.css index 575a6ac..70c1b36 100644 --- a/src/pages/ScoreSheet.module.css +++ b/src/pages/ScoreSheet.module.css @@ -49,6 +49,10 @@ border-top: 1px solid var(--color-parchment-border); } +.winnerCell { + background: rgba(74, 158, 106, 0.15); +} + /* Small red "New Game" button in header top-right */ .newGameBtn { background: #d94f4f; diff --git a/src/pages/ScoreSheet.tsx b/src/pages/ScoreSheet.tsx index b6fda34..69aaf4e 100644 --- a/src/pages/ScoreSheet.tsx +++ b/src/pages/ScoreSheet.tsx @@ -16,6 +16,8 @@ export default function ScoreSheet({ game, onScoreRound, onNewGame }: Props) { const totals = computeRunningTotals(game.rounds) const gameOver = isGameOver(totals) + const lastTotals = totals[totals.length - 1] ?? [] + const winnerIndex = gameOver ? lastTotals.indexOf(Math.max(...lastTotals)) : -1 const newGameButton = (