From 875e9c879514c40b1433c8f97d1e0fe67994d4cc Mon Sep 17 00:00:00 2001 From: Frank Schwenk Date: Fri, 20 Jun 2025 13:35:42 +0200 Subject: [PATCH] feat: Implement rematch functionality Refs #17 Adds a 'Rematch' button to the game completion modal. Introduces a 'handleRematch' function in 'App.jsx' to create a new game with the same players and settings as the previous game. The 'onRematch' handler is passed down to the 'GameCompletionModal' component. Adds '.gitea' to '.gitignore' to prevent tracking local issue context. --- .gitignore | 2 +- src/components/App.jsx | 17 +++++++++++++++++ src/components/GameCompletionModal.jsx | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 87cfc77..c1c2679 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ pnpm-debug.log* .idea/ .gitea -dev/ \ No newline at end of file +dev/.gitea diff --git a/src/components/App.jsx b/src/components/App.jsx index acbc37d..a15375a 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -117,6 +117,22 @@ const App = () => { setScreen('game-detail'); }, [currentGameId]); + const handleRematch = useCallback(() => { + const completedGame = games.find(g => g.id === currentGameId); + if (!completedGame) return; + + const newId = handleCreateGame({ + player1: completedGame.player1, + player2: completedGame.player2, + player3: completedGame.player3, + gameType: completedGame.gameType, + raceTo: completedGame.raceTo, + }); + + setCompletionModal({ open: false, game: null }); + showGameDetail(newId); + }, [games, currentGameId, handleCreateGame, showGameDetail]); + // Delete game const handleDeleteGame = useCallback((id) => { setModal({ open: true, gameId: id }); @@ -258,6 +274,7 @@ const App = () => { game={completionModal.game} onConfirm={handleConfirmCompletion} onClose={() => setCompletionModal({ open: false, game: null })} + onRematch={handleRematch} /> diff --git a/src/components/GameCompletionModal.jsx b/src/components/GameCompletionModal.jsx index ff096db..641006d 100644 --- a/src/components/GameCompletionModal.jsx +++ b/src/components/GameCompletionModal.jsx @@ -9,9 +9,10 @@ import styles from './GameCompletionModal.module.css'; * @param {object} props.game * @param {Function} props.onConfirm * @param {Function} props.onClose + * @param {Function} props.onRematch * @returns {import('preact').VNode|null} */ -const GameCompletionModal = ({ open, game, onConfirm, onClose }) => { +const GameCompletionModal = ({ open, game, onConfirm, onClose, onRematch }) => { if (!open || !game) return null; const playerNames = [game.player1, game.player2, game.player3].filter(Boolean); const scores = [game.score1, game.score2, game.score3].filter((_, i) => playerNames[i]); @@ -41,6 +42,7 @@ const GameCompletionModal = ({ open, game, onConfirm, onClose }) => {
+