Skip to content

Commit

Permalink
lobby state immer
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Oct 5, 2024
1 parent 1058972 commit af36a61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/main/client/src/feature/lobby/Lobby.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ function DetailNavigation({detail, setDetail}) {
onClick={() => setDetail(id)}
disabled={id === detail}
className={twJoin(
"px-2 py-2 rounded-lg border-2 hover:border-sky-700",
"px-2 py-2 rounded-lg border-2",
id === detail && "border-slate-600",
id !== detail && "border-transparent hover:bg-stone-800",
id !== detail && "border-transparent hover:border-sky-700",
)}>{label}</button>
))}
</div>
Expand Down
27 changes: 16 additions & 11 deletions src/main/client/src/feature/lobby/lobbyState.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {
produce,
} from "immer"

export function initialState() {
return {
stack: [],
stack: [], // newgame, accept
proposals: [],
}
}

Expand All @@ -11,13 +16,13 @@ function setOpen(state, el, kind, data) {
if (state.stack.some(obj => obj.kind === kind)) {
return state
}
return {
stack: [...state.stack, {
return produce(state, draft => {
draft.stack = [...state.stack, {
kind: kind,
el: el,
data: data,
}],
}
}]
})
}

export function getZindex({stack}, kind) {
Expand Down Expand Up @@ -52,9 +57,9 @@ export function closeLobbyPopup(state) {
}
let newStack = [...state.stack]
newStack.pop()
return {
stack: newStack,
}
return produce(state, draft => {
draft.stack = newStack
})
}

export function handleLobbyClick(state, event) {
Expand All @@ -69,7 +74,7 @@ export function handleLobbyClick(state, event) {
}
let newStack = [...state.stack]
newStack.pop()
return {
stack: newStack,
}
return produce(state, draft => {
draft.stack = newStack
})
}

0 comments on commit af36a61

Please sign in to comment.