fix: prevent route celebration from immediately reappearing
Fixed race condition where route celebration modal would immediately reappear after clicking 'Continue Journey'. Root cause: trainPosition stayed >= 100 while showRouteCelebration was toggled, causing the interval check to re-trigger COMPLETE_ROUTE. Solution: 1. START_NEW_ROUTE now resets showRouteCelebration to false 2. Removed setTimeout delay and HIDE_ROUTE_CELEBRATION action 3. Single atomic state update prevents race condition Now continuing to next route works smoothly without modal flickering. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -162,21 +162,16 @@ export function GameDisplay() {
|
||||
const handleContinueToNextRoute = () => {
|
||||
const nextRoute = state.currentRoute + 1
|
||||
|
||||
// Hide celebration
|
||||
dispatch({ type: 'HIDE_ROUTE_CELEBRATION' })
|
||||
// Start new route (this also hides celebration)
|
||||
dispatch({
|
||||
type: 'START_NEW_ROUTE',
|
||||
routeNumber: nextRoute,
|
||||
stations: state.stations // Keep same stations for now
|
||||
})
|
||||
|
||||
// Generate new track and passengers for next route
|
||||
setTimeout(() => {
|
||||
dispatch({
|
||||
type: 'START_NEW_ROUTE',
|
||||
routeNumber: nextRoute,
|
||||
stations: state.stations // Keep same stations for now
|
||||
})
|
||||
|
||||
// Generate new passengers
|
||||
const newPassengers = generatePassengers(state.stations)
|
||||
dispatch({ type: 'GENERATE_PASSENGERS', passengers: newPassengers })
|
||||
}, 100)
|
||||
// Generate new passengers
|
||||
const newPassengers = generatePassengers(state.stations)
|
||||
dispatch({ type: 'GENERATE_PASSENGERS', passengers: newPassengers })
|
||||
}
|
||||
|
||||
if (!state.currentQuestion) return null
|
||||
|
||||
@@ -375,7 +375,8 @@ function gameReducer(state: GameState, action: GameAction): GameState {
|
||||
currentRoute: action.routeNumber,
|
||||
stations: action.stations,
|
||||
trainPosition: 0,
|
||||
deliveredPassengers: 0
|
||||
deliveredPassengers: 0,
|
||||
showRouteCelebration: false
|
||||
}
|
||||
|
||||
case 'COMPLETE_ROUTE':
|
||||
|
||||
Reference in New Issue
Block a user