Improved handling ws connection and redirect
This commit is contained in:
parent
53a07b21b0
commit
0317a3343c
10 changed files with 100 additions and 50 deletions
|
@ -45,6 +45,7 @@ export type Action = {
|
|||
full: (newProps: GamePropsSchema) => void
|
||||
leave: (cb: () => void) => void
|
||||
setIsReady: (payload: { i: number; isReady: boolean }) => void
|
||||
starting: () => void
|
||||
setIsConnected: (payload: { i: number; isConnected: boolean }) => void
|
||||
reset: () => void
|
||||
}
|
||||
|
@ -159,6 +160,17 @@ export const useGameProps = create<State & Action>()(
|
|||
state.userStates[i].isConnected = true
|
||||
})
|
||||
),
|
||||
starting: () =>
|
||||
set(
|
||||
produce((state: State) => {
|
||||
if (state.payload?.game?.state !== "lobby") return
|
||||
state.payload.game.state = "starting"
|
||||
state.userStates = state.userStates.map((e) => ({
|
||||
...e,
|
||||
isReady: false,
|
||||
}))
|
||||
})
|
||||
),
|
||||
setIsConnected: ({ i, isConnected }) =>
|
||||
set(
|
||||
produce((state: State) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue