Skip to content

Commit 1058972

Browse files
committed
z index from stack
1 parent bef5b0e commit 1058972

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
useAuthStore,
3434
} from "src/store.js"
3535
import {
36-
checkNewGameOpen,
36+
getZindex,
3737
setNewGameOpen,
3838
handleLobbyClick,
3939
closeLobbyPopup,
@@ -53,7 +53,7 @@ const detailData = [
5353

5454
export function Lobby() {
5555
let [lobbyState, setLobbyState] = useState(initialState())
56-
let isNewGameOpen = checkNewGameOpen(lobbyState)
56+
let zNewGame = getZindex(lobbyState, "newgame")
5757
let [detail, setDetail] = useState("open")
5858
let stompClient = useContext(StompContext)
5959
let navigate = useNavigate()
@@ -89,20 +89,19 @@ export function Lobby() {
8989
return (
9090
<div onClick={(event) => setLobbyState(handleLobbyClick(lobbyState, event))} className="h-full">
9191
<div className={twJoin(
92-
"mt-2 py-2 pr-4 gap-x-1",
93-
isNewGameOpen && "",
94-
!isNewGameOpen && "border-transparent",
92+
"mt-2 py-2 pr-4",
9593
)}>
9694
<NewGameDialog
95+
zNewGame={zNewGame}
9796
lobbyState={lobbyState}
9897
setLobbyState={setLobbyState}
9998
newGameRef={newGameRef}
10099
onNewGame={onNewGame}
101100
onStartEdit={onStartEdit} />
102-
<button disabled={isNewGameOpen} className={twJoin(
101+
<button disabled={zNewGame !== 0} className={twJoin(
103102
"ml-2 border-2 border-transparent px-4 py-2 rounded-lg",
104-
isNewGameOpen && "bg-gray-400",
105-
!isNewGameOpen && "hover:border-sky-700",
103+
zNewGame && "bg-gray-400",
104+
!zNewGame && "hover:border-sky-700",
106105
)}
107106
onClick={(event) => {
108107
setLobbyState(setNewGameOpen(lobbyState, newGameRef.current))
@@ -125,11 +124,10 @@ export function Lobby() {
125124
)
126125
}
127126

128-
function NewGameDialog({lobbyState, setLobbyState, onNewGame, onStartEdit, newGameRef}) {
127+
function NewGameDialog({zNewGame, lobbyState, setLobbyState, onNewGame, onStartEdit, newGameRef}) {
129128
let dimRef = useRef(9)
130129
let timeRef = useRef(10)
131130
let [edit, setEdit] = useState(false)
132-
let isNewGameOpen = checkNewGameOpen(lobbyState)
133131
return (
134132
<form onSubmit={(e) => {
135133
e.preventDefault()
@@ -141,10 +139,13 @@ function NewGameDialog({lobbyState, setLobbyState, onNewGame, onStartEdit, newGa
141139
}
142140
}}>
143141
<div ref={newGameRef}
142+
style={{
143+
zIndex: zNewGame,
144+
}}
144145
className={twJoin(
145-
!isNewGameOpen && "hidden",
146-
"absolute ml-40 bg-slate-800 border-2 border-slate-600 rounded-lg z-10 px-3 py-2",
147-
)}>
146+
!zNewGame && "hidden",
147+
"absolute ml-40 bg-slate-800 border-2 border-slate-600 rounded-lg px-3 py-2",
148+
)}>
148149
<div className="absolute top-1 right-1">
149150
<button onClick={() => setLobbyState(closeLobbyPopup(lobbyState))} className="text-stone-100 hover:text-stone-300">
150151
<IconContext.Provider value={{ size: "1.25em" }}>

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
stopPropagation,
3636
} from "src/util.js"
3737
import {
38+
getZindex,
3839
getAcceptData,
3940
setAcceptDialogOpen,
4041
} from "./lobbyState.js"
@@ -96,10 +97,10 @@ export function OpenGames({lobbyState, setLobbyState}) {
9697
))}
9798
</div>
9899
<AcceptDialog
100+
lobbyState={lobbyState}
99101
acceptableGame={acceptableGame}
100102
onAccept={onAccept}
101-
acceptDialogRef={acceptDialogRef}
102-
/>
103+
acceptDialogRef={acceptDialogRef} />
103104
</div>
104105
)
105106
}
@@ -108,11 +109,6 @@ function OpenGame({game, onClick}) {
108109
let dimRef = useRef()
109110
let auth = useAuthStore(state => state.auth)
110111
let disabled = auth.name === game.user
111-
let classes = twJoin(
112-
"contents",
113-
"*:py-3",
114-
!disabled && "cursor-pointer *:hover:bg-sky-200 *:hover:text-black",
115-
)
116112
return (
117113
<div
118114
onClick={disabled ? undefined : (event) => {
@@ -125,7 +121,11 @@ function OpenGame({game, onClick}) {
125121
},
126122
})
127123
}}
128-
className={classes}
124+
className={twJoin(
125+
"contents",
126+
"*:py-3",
127+
!disabled && "cursor-pointer *:hover:bg-sky-200 *:hover:text-black",
128+
)}
129129
key={game.id}>
130130
<div className="pl-3 pr-1 rounded-l-lg">{game.user}</div>
131131
<div className="px-1">
@@ -138,10 +138,11 @@ function OpenGame({game, onClick}) {
138138
)
139139
}
140140

141-
function AcceptDialog({onAccept, acceptableGame, acceptDialogRef}) {
141+
function AcceptDialog({lobbyState, onAccept, acceptableGame, acceptDialogRef}) {
142142
let [isFlip, setFlip] = useState(false)
143143
let [handi, setHandi] = useState(1)
144144
let auth = useAuthStore(state => state.auth)
145+
let zAccept = getZindex(lobbyState, "accept")
145146
return (
146147
<Form
147148
forwardedRef={acceptDialogRef}
@@ -151,12 +152,13 @@ function AcceptDialog({onAccept, acceptableGame, acceptDialogRef}) {
151152
handicap: handi === 1 ? 0 : handi,
152153
})}
153154
style={{
155+
zIndex: zAccept,
154156
top: acceptableGame?.rect.top || 0,
155157
left: Math.trunc(acceptableGame?.rect.right || 0) + 16,
156158
}}
157159
className={twJoin(
158-
!acceptableGame && "hidden",
159-
"absolute bg-sky-200 px-4 py-3 rounded-lg z-8 flex flex-col",
160+
!zAccept && "hidden",
161+
"absolute bg-sky-200 px-4 py-3 rounded-lg flex flex-col",
160162
)}>
161163
<div className="text-black">
162164
<button type="button" className="inline-flex" onClick={() => setFlip(!isFlip)}>

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@ function setOpen(state, el, kind, data) {
2020
}
2121
}
2222

23-
export function checkNewGameOpen({stack}) {
24-
return stack.some(obj => obj.kind === "newgame")
23+
export function getZindex({stack}, kind) {
24+
for (let i = 0; i < stack.length; i++) {
25+
if (stack[i].kind === kind) {
26+
return 5 + i
27+
}
28+
}
29+
return 0
2530
}
2631

2732
export function setNewGameOpen(state, el) {
2833
return setOpen(state, el, "newgame")
2934
}
3035

3136
export function getAcceptData({stack}) {
32-
if (!stack.length) {
33-
return undefined
34-
}
35-
let result = stack.filter(obj => obj.kind === "accept")
36-
if (!result.length) {
37-
return undefined
37+
for (let i = 0; i < stack.length; i++) {
38+
if (stack[i].kind === "accept") {
39+
return stack[i].data
40+
}
3841
}
39-
return result[0].data
42+
return undefined
4043
}
4144

4245
export function setAcceptDialogOpen(state, el, data) {

0 commit comments

Comments
 (0)