mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
refactor: add typescript & pnpm workspace & docker file
This commit is contained in:
37
packages/web/src/stores/player.tsx
Normal file
37
packages/web/src/stores/player.tsx
Normal 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 }),
|
||||
}))
|
||||
Reference in New Issue
Block a user