@@ -124,23 +124,32 @@ const WebsocketHandler = () => {
124
124
// On round completion we need to display the last round to the user
125
125
const processRoundCompleted = async (
126
126
game : GameState ,
127
- previousRound : Round ,
127
+ previousRound ? : Round ,
128
128
) => {
129
129
// Disable actions by setting isMyGo to false
130
130
dispatch ( disableActions ( ) )
131
131
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
+ }
144
153
145
154
// Finally update the game with the latest state
146
155
shuffleSound ( )
@@ -186,7 +195,9 @@ const WebsocketHandler = () => {
186
195
case "ROUND_COMPLETED" :
187
196
await processRoundCompleted (
188
197
action . gameState ,
189
- action . transitionData as Round ,
198
+ action . transitionData
199
+ ? ( action . transitionData as Round )
200
+ : undefined ,
190
201
)
191
202
break
192
203
case "BUY_CARDS" :
0 commit comments