@@ -8,7 +8,7 @@ import reverseOpponentStones from "@/_utilities/reverseOpponentStones";
8
8
import graphQLError from "@/_utilities/graphQLError" ;
9
9
import { GET_GAME_BY_ID , GET_MOVES_BY_GAME_ID } from "@/_graphql/queries" ;
10
10
import { CREATE_MOVES , UPDATE_GAME } from "@/_graphql/mutations" ;
11
- import { GAME_MOVED , GAME_RESTARTED , GAME_UPDATED } from "@/_graphql/subscriptions" ;
11
+ import { GAME_MOVED , GAME_UPDATED } from "@/_graphql/subscriptions" ;
12
12
import getActiveGamerData , { IActiveGamerData } from "@/_utilities/getActiveGamerData" ;
13
13
import useDeepCompareMemoize from "@/_hooks/useDeepCompareMemoize" ;
14
14
import useGameResultModal from "@/_store/useGameResultModal" ;
@@ -21,7 +21,6 @@ import {
21
21
IStone ,
22
22
IStones ,
23
23
SubscriptionGameMovedData ,
24
- SubscriptionGameRestartedData ,
25
24
SubscriptionGameUpdatedData
26
25
} from "@/_types" ;
27
26
import GameResultModal from "./modal/GameResultModal" ;
@@ -95,32 +94,27 @@ export default function Board() {
95
94
onError : graphQLError
96
95
} ) ;
97
96
98
- useSubscription < SubscriptionGameMovedData > ( GAME_MOVED , {
99
- variables : {
100
- gameID : id
101
- } ,
102
- onData : ( { data : { data } } ) => {
103
- if ( data ?. moves ) {
104
- const moves = data . moves ;
105
- setBoard ( prevState => prevState . map ( cell => {
106
- const move = moves . find ( move => move . row == cell . row && move . col == cell . col ) ;
107
- return move ? move : cell
108
- } ) )
109
- }
110
- } ,
111
- onError : graphQLError
112
- } ) ;
113
-
114
- useSubscription < SubscriptionGameRestartedData > ( GAME_RESTARTED , {
97
+ useSubscription < SubscriptionGameMovedData > ( GAME_MOVED , {
115
98
variables : {
116
99
gameID : id
117
100
} ,
118
101
onData : ( { data : { data } } ) => {
119
102
if ( data ?. game ) {
120
- setBoard ( createBoard )
103
+ const game = data . game ;
104
+ if ( game . isGameRestarted ) {
105
+ setBoard ( prevState => prevState . map ( cell => {
106
+ const move = game . moves . find ( move => move . row == cell . row && move . col == cell . col ) ;
107
+ return move ? move : { ...cell , gamer : null , gamerID : null }
108
+ } ) )
109
+ } else {
110
+ setBoard ( prevState => prevState . map ( cell => {
111
+ const move = game . moves . find ( move => move . row == cell . row && move . col == cell . col ) ;
112
+ return move ? move : cell
113
+ } ) )
114
+ }
121
115
}
122
116
} ,
123
- onError : graphQLError
117
+ onError : graphQLError
124
118
} ) ;
125
119
126
120
const handleHint = useCallback ( async ( move : IStone ) => {
@@ -197,7 +191,7 @@ export default function Board() {
197
191
variables : {
198
192
data : {
199
193
_id : id as string ,
200
- moveOrder : nextMoveOrderID ( memoizedGame as IGame ) ,
194
+ moveOrder : nextMoveOrderID ( memoizedGame as IGame ) ,
201
195
gamers : updatedGamers
202
196
}
203
197
}
0 commit comments