Improved handling ws connection and redirect

This commit is contained in:
aronmal 2023-06-11 00:37:12 +02:00
parent 53a07b21b0
commit 0317a3343c
Signed by: aronmal
GPG key ID: 816B7707426FC612
10 changed files with 100 additions and 50 deletions

View file

@ -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) => {