feat: player status store for online/busy/available state management
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
import { create } from "zustand"
|
||||||
|
import type { Player } from "@/lib/types"
|
||||||
|
|
||||||
|
type PlayerStatus = Player["status"]
|
||||||
|
|
||||||
|
interface PlayerStatusState {
|
||||||
|
statuses: Record<string, PlayerStatus>
|
||||||
|
setStatus: (playerId: string, status: PlayerStatus) => void
|
||||||
|
getStatus: (playerId: string) => PlayerStatus | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export const usePlayerStatusStore = create<PlayerStatusState>((set, get) => ({
|
||||||
|
statuses: {
|
||||||
|
u2: "available",
|
||||||
|
u4: "busy",
|
||||||
|
u5: "available",
|
||||||
|
},
|
||||||
|
setStatus: (playerId, status) =>
|
||||||
|
set((state) => ({
|
||||||
|
statuses: { ...state.statuses, [playerId]: status },
|
||||||
|
})),
|
||||||
|
getStatus: (playerId) => get().statuses[playerId],
|
||||||
|
}))
|
||||||
Reference in New Issue
Block a user