File size: 966 Bytes
9a42933
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use client"

import { create } from "zustand"

import { CurrentPanel, Party, Player } from "@/types"
import { newParty } from "./newParty"
import { newPlayer } from "./newPlayer"

// note: this should not be used in server-side template or we will have some trouble
export const useStore = create<{
  panel: CurrentPanel
  isLoading: boolean
  party: Party
  player: Player
  setLoading: (isLoading: boolean) => void
  setPanel: (panel: CurrentPanel) => void
  setParty: (party: Partial<Party>) => void
  setPlayer: (player: Player) => void
}>((set, get) => ({
  panel: "join",
  isLoading: false,
  party: newParty(),
  player: newPlayer(),
  setLoading: (isLoading: boolean) => {
    set({ isLoading })
  },
  setPanel: (panel: CurrentPanel) => {
    set({ panel })
  },
  setParty: (party: Partial<Party>) => {
    set({
      party: {
        ...get().party,
        ...party,
      }
    })
  },
  setPlayer: (player: Player) => {
    set({ player })
  }
}))