Skip to content

Commit 706714f

Browse files
fix: don't change games when new moves come in
1 parent d66f29e commit 706714f

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/hooks/useBroadcastController.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@ export const useBroadcastController = (): BroadcastStreamController => {
337337
const existingGameState = gameStates.current.get(game.id)
338338
const newLiveGame = createLiveGameFromBroadcastGame(game)
339339

340-
// Play sound for new moves if game was already loaded
340+
// Play sound for new moves only if this is the currently selected game
341341
if (
342+
currentGame &&
343+
game.id === currentGame.id &&
342344
existingGameState &&
343345
newLiveGame.moves.length > existingGameState.moves.length
344346
) {
@@ -362,16 +364,17 @@ export const useBroadcastController = (): BroadcastStreamController => {
362364
return newRoundData
363365
})
364366

365-
// Update current game if it exists in the new data
367+
// Update current game data if it's in the update, but don't switch to a different game
366368
if (currentGame) {
367-
const updatedGame = parseResult.games.find(
369+
const updatedCurrentGame = parseResult.games.find(
368370
(g) => g.id === currentGame.id,
369371
)
370-
if (updatedGame) {
371-
setCurrentGame(updatedGame)
372+
if (updatedCurrentGame) {
373+
// Update the currently selected game with new data (including clocks)
374+
setCurrentGame(updatedCurrentGame)
372375
}
373376
} else if (parseResult.games.length > 0) {
374-
// Auto-select first game if none selected
377+
// Auto-select first game only if no game is currently selected
375378
setCurrentGame(parseResult.games[0])
376379
}
377380

0 commit comments

Comments
 (0)