refactor: add typescript & pnpm workspace & docker file

This commit is contained in:
Ralex
2025-10-16 23:12:40 +02:00
parent 8f73241f34
commit edb7146d6d
122 changed files with 7568 additions and 8502 deletions

View File

@@ -0,0 +1,44 @@
import { StatusDataMap } from "@rahoot/common/types/game/status"
import { create } from "zustand"
export type Status<T> = {
[K in keyof T]: { name: K; data: T[K] }
}[keyof T]
export function createStatus<T, K extends keyof T>(
name: K,
data: T[K],
): Status<T> {
return { name, data }
}
type GameStore<T> = {
status: Status<T>
// eslint-disable-next-line no-unused-vars
setStatus: <K extends keyof T>(name: K, data: T[K]) => void
resetStatus: () => void
}
export const usePlayerGameStore = create<GameStore<StatusDataMap>>((set) => {
const initialStatus = createStatus<StatusDataMap, "WAIT">("WAIT", {
text: "Waiting for the players",
})
return {
status: initialStatus,
setStatus: (name, data) => set({ status: createStatus(name, data) }),
resetStatus: () => set({ status: initialStatus }),
}
})
export const useManagerGameStore = create<GameStore<StatusDataMap>>((set) => {
const initialStatus = createStatus<StatusDataMap, "SHOW_ROOM">("SHOW_ROOM", {
text: "Waiting for the players",
})
return {
status: initialStatus,
setStatus: (name, data) => set({ status: createStatus(name, data) }),
resetStatus: () => set({ status: initialStatus }),
}
})

View File

@@ -0,0 +1,37 @@
/* eslint-disable no-unused-vars */
import { create } from "zustand"
type PlayerState = {
gameId?: string
username?: string
points?: number
}
type PlayerStore = {
player: PlayerState | null
login: (gameId: string) => void
join: (username: string) => void
updatePoints: (points: number) => void
logout: () => void
}
export const usePlayerStore = create<PlayerStore>((set) => ({
player: null,
login: (username) =>
set((state) => ({
player: { ...state.player, username },
})),
join: (gameId) =>
set((state) => ({
player: { ...state.player, gameId, points: 0 },
})),
updatePoints: (points) =>
set((state) => ({
player: { ...state.player, points },
})),
logout: () => set({ player: null }),
}))