fix(card-sorting): New Game now restarts with same settings instantly
Changed "New Game" behavior to immediately start a new game with the current settings, without going through the setup page. Changes: - Removed the gamePhase === 'playing' guard in startGame() - This allows starting a new game even when already playing - Still prevents rapid double-sends within 500ms - Simplified GameComponent's onNewGame handler back to just calling startGame() Now when "New Game" is clicked: - Immediately starts a fresh game - Uses the same settings (card count, show numbers, time limit, game mode) - No interruption with the setup screen This provides a smoother "play again" experience for quick restarts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f3f6eca1db
commit
f3687ed236
|
|
@ -404,13 +404,11 @@ export function CardSortingProvider({ children }: { children: ReactNode }) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent multiple simultaneous START_GAME moves when multiple clients
|
// Prevent rapid double-sends within 500ms to avoid duplicate game starts
|
||||||
// click "Play Again" at the same time. Only allow if we're NOT already starting/in a game.
|
|
||||||
// Also check if we just started a game (within 500ms) to prevent rapid double-sends.
|
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const justStarted = state.gameStartTime && now - state.gameStartTime < 500
|
const justStarted = state.gameStartTime && now - state.gameStartTime < 500
|
||||||
|
|
||||||
if (state.gamePhase === 'playing' || justStarted) {
|
if (justStarted) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,16 +41,7 @@ export function GameComponent() {
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
onNewGame={() => {
|
onNewGame={() => {
|
||||||
// If currently playing, go to setup first to clean up, then start immediately
|
startGame()
|
||||||
if (state.gamePhase === 'playing') {
|
|
||||||
goToSetup()
|
|
||||||
// Use a small delay to let setup phase render, then start new game
|
|
||||||
setTimeout(() => {
|
|
||||||
startGame()
|
|
||||||
}, 100)
|
|
||||||
} else {
|
|
||||||
startGame()
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StandardGameLayout>
|
<StandardGameLayout>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue