Skip to content

Commit af36a61

Browse files
committed
lobby state immer
1 parent 1058972 commit af36a61

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/main/client/src/feature/lobby/Lobby.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ function DetailNavigation({detail, setDetail}) {
214214
onClick={() => setDetail(id)}
215215
disabled={id === detail}
216216
className={twJoin(
217-
"px-2 py-2 rounded-lg border-2 hover:border-sky-700",
217+
"px-2 py-2 rounded-lg border-2",
218218
id === detail && "border-slate-600",
219-
id !== detail && "border-transparent hover:bg-stone-800",
219+
id !== detail && "border-transparent hover:border-sky-700",
220220
)}>{label}</button>
221221
))}
222222
</div>

src/main/client/src/feature/lobby/lobbyState.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import {
2+
produce,
3+
} from "immer"
4+
15
export function initialState() {
26
return {
3-
stack: [],
7+
stack: [], // newgame, accept
8+
proposals: [],
49
}
510
}
611

@@ -11,13 +16,13 @@ function setOpen(state, el, kind, data) {
1116
if (state.stack.some(obj => obj.kind === kind)) {
1217
return state
1318
}
14-
return {
15-
stack: [...state.stack, {
19+
return produce(state, draft => {
20+
draft.stack = [...state.stack, {
1621
kind: kind,
1722
el: el,
1823
data: data,
19-
}],
20-
}
24+
}]
25+
})
2126
}
2227

2328
export function getZindex({stack}, kind) {
@@ -52,9 +57,9 @@ export function closeLobbyPopup(state) {
5257
}
5358
let newStack = [...state.stack]
5459
newStack.pop()
55-
return {
56-
stack: newStack,
57-
}
60+
return produce(state, draft => {
61+
draft.stack = newStack
62+
})
5863
}
5964

6065
export function handleLobbyClick(state, event) {
@@ -69,7 +74,7 @@ export function handleLobbyClick(state, event) {
6974
}
7075
let newStack = [...state.stack]
7176
newStack.pop()
72-
return {
73-
stack: newStack,
74-
}
77+
return produce(state, draft => {
78+
draft.stack = newStack
79+
})
7580
}

0 commit comments

Comments
 (0)