feat: improve reconnect, add ESLint configuration for common and socket

This commit is contained in:
Ralex
2025-10-19 00:37:26 +02:00
parent 8bdb8f47ef
commit 96bff164c0
36 changed files with 1571 additions and 677 deletions

View File

@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
import { Player } from "@rahoot/common/types/game"
import { StatusDataMap } from "@rahoot/common/types/game/status"
import { createStatus, Status } from "@rahoot/web/utils/createStatus"
@@ -9,22 +8,26 @@ type ManagerStore<T> = {
status: Status<T>
players: Player[]
setGameId: (gameId: string | null) => void
setStatus: <K extends keyof T>(name: K, data: T[K]) => void
setGameId: (_gameId: string | null) => void
setStatus: <K extends keyof T>(_name: K, _data: T[K]) => void
resetStatus: () => void
setPlayers: (_players: Player[]) => void
setPlayers: (players: Player[]) => void
reset: () => void
}
const initialStatus = createStatus<StatusDataMap, "SHOW_ROOM">("SHOW_ROOM", {
text: "Waiting for the players",
})
export const useManagerStore = create<ManagerStore<StatusDataMap>>((set) => ({
const initialState = {
gameId: null,
status: initialStatus,
players: [],
}
export const useManagerStore = create<ManagerStore<StatusDataMap>>((set) => ({
...initialState,
setGameId: (gameId) => set({ gameId }),
@@ -32,4 +35,6 @@ export const useManagerStore = create<ManagerStore<StatusDataMap>>((set) => ({
resetStatus: () => set({ status: initialStatus }),
setPlayers: (players) => set({ players }),
reset: () => set(initialState),
}))

View File

@@ -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),
}))

View File

@@ -1,10 +1,9 @@
/* eslint-disable no-unused-vars */
import { GameUpdateQuestion } from "@rahoot/common/types/game"
import { create } from "zustand"
type QuestionStore = {
questionStates: GameUpdateQuestion | null
setQuestionStates: (state: GameUpdateQuestion) => void
setQuestionStates: (_state: GameUpdateQuestion) => void
}
export const useQuestionStore = create<QuestionStore>((set) => ({