Skip to content

Commit 41d47f2

Browse files
committed
Fixing behaviour when nobody calls
1 parent 22387b4 commit 41d47f2

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/components/Game/WebsocketManager.tsx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,32 @@ const WebsocketHandler = () => {
124124
// On round completion we need to display the last round to the user
125125
const processRoundCompleted = async (
126126
game: GameState,
127-
previousRound: Round,
127+
previousRound?: Round,
128128
) => {
129129
// Disable actions by setting isMyGo to false
130130
dispatch(disableActions())
131131

132-
// Show the last card of the penultimate round being played
133-
playCardSound()
134-
const penultimateHand = previousRound.completedHands.pop()
135-
if (!penultimateHand) throw Error("Failed to get the penultimate round")
136-
dispatch(updatePlayedCards(penultimateHand.playedCards))
137-
await new Promise(r => setTimeout(r, 4000))
138-
139-
// Next show the final round being played
140-
playCardSound()
141-
dispatch(updatePlayedCards(previousRound.currentHand.playedCards))
142-
dispatch(updateMyCards([]))
143-
await new Promise(r => setTimeout(r, 6000))
132+
// Previous round will be undefined nobody called
133+
if (previousRound) {
134+
// Show the last card of the penultimate round being played
135+
playCardSound()
136+
const penultimateHand = previousRound.completedHands.pop()
137+
if (!penultimateHand)
138+
throw Error("Failed to get the penultimate round")
139+
dispatch(updatePlayedCards(penultimateHand.playedCards))
140+
await new Promise(r => setTimeout(r, 4000))
141+
142+
// Next show the final round being played
143+
playCardSound()
144+
dispatch(updatePlayedCards(previousRound.currentHand.playedCards))
145+
dispatch(updateMyCards([]))
146+
await new Promise(r => setTimeout(r, 6000))
147+
} else {
148+
enqueueSnackbar("Nobody called. Redealing....", {
149+
variant: "info",
150+
})
151+
await new Promise(r => setTimeout(r, 2000))
152+
}
144153

145154
// Finally update the game with the latest state
146155
shuffleSound()
@@ -186,7 +195,9 @@ const WebsocketHandler = () => {
186195
case "ROUND_COMPLETED":
187196
await processRoundCompleted(
188197
action.gameState,
189-
action.transitionData as Round,
198+
action.transitionData
199+
? (action.transitionData as Round)
200+
: undefined,
190201
)
191202
break
192203
case "BUY_CARDS":

0 commit comments

Comments
 (0)