mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
feat: improve reconnect, add ESLint configuration for common and socket
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { StatusDataMap } from "@rahoot/common/types/game/status"
|
||||
import { createStatus, Status } from "@rahoot/web/utils/createStatus"
|
||||
import { create } from "zustand"
|
||||
@@ -13,27 +12,30 @@ type PlayerStore<T> = {
|
||||
player: PlayerState | null
|
||||
status: Status<T>
|
||||
|
||||
setGameId: (gameId: string | null) => void
|
||||
setGameId: (_gameId: string | null) => void
|
||||
|
||||
setPlayer: (state: PlayerState) => void
|
||||
login: (gameId: string) => void
|
||||
join: (username: string) => void
|
||||
updatePoints: (points: number) => void
|
||||
logout: () => void
|
||||
setPlayer: (_state: PlayerState) => void
|
||||
login: (_gameId: string) => void
|
||||
join: (_username: string) => void
|
||||
updatePoints: (_points: number) => void
|
||||
|
||||
setStatus: <K extends keyof T>(name: K, data: T[K]) => void
|
||||
resetStatus: () => void
|
||||
setStatus: <K extends keyof T>(_name: K, _data: T[K]) => void
|
||||
|
||||
reset: () => void
|
||||
}
|
||||
|
||||
const initialStatus = createStatus<StatusDataMap, "WAIT">("WAIT", {
|
||||
text: "Waiting for the players",
|
||||
})
|
||||
|
||||
export const usePlayerStore = create<PlayerStore<StatusDataMap>>((set) => ({
|
||||
const initialState = {
|
||||
gameId: null,
|
||||
player: null,
|
||||
status: initialStatus,
|
||||
currentQuestion: null,
|
||||
}
|
||||
|
||||
export const usePlayerStore = create<PlayerStore<StatusDataMap>>((set) => ({
|
||||
...initialState,
|
||||
|
||||
setGameId: (gameId) => set({ gameId }),
|
||||
|
||||
@@ -55,8 +57,7 @@ export const usePlayerStore = create<PlayerStore<StatusDataMap>>((set) => ({
|
||||
player: { ...state.player, points },
|
||||
})),
|
||||
|
||||
logout: () => set({ player: null }),
|
||||
|
||||
setStatus: (name, data) => set({ status: createStatus(name, data) }),
|
||||
resetStatus: () => set({ status: initialStatus }),
|
||||
|
||||
reset: () => set(initialState),
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user