Skip to content

Commit

Permalink
show timesetting
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Oct 4, 2024
1 parent 66b6353 commit bef5b0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
30 changes: 12 additions & 18 deletions src/main/client/src/feature/lobby/OpenGames.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
stopPropagation,
} from "src/util.js"
import {
getAcceptDialog,
getAcceptData,
setAcceptDialogOpen,
} from "./lobbyState.js"
import {
Expand All @@ -44,7 +44,7 @@ import {

export function OpenGames({lobbyState, setLobbyState}) {
let [openGames, setOpenGames] = useState([])
let acceptDialog = getAcceptDialog(lobbyState)
let acceptableGame = getAcceptData(lobbyState)
let stompClient = useContext(StompContext)
let navigate = useNavigate()
let auth = useAuthStore(state => state.auth)
Expand Down Expand Up @@ -84,22 +84,19 @@ export function OpenGames({lobbyState, setLobbyState}) {
}), [auth, navigate])
return (
<div>
<div className="grid grid-cols-[max-content_max-content]">
<div className="grid grid-cols-[max-content_max-content_max-content]">
{openGames.map((game) => (
<OpenGame
game={game}
onClick={(event, acceptableGame) => {
if (acceptDialog) {
return
}
setLobbyState(setAcceptDialogOpen(lobbyState, acceptDialogRef.current, acceptableGame))
stopPropagation(event)
}}
key={game.id} />
))}
</div>
<AcceptDialog
acceptDialog={acceptDialog}
acceptableGame={acceptableGame}
onAccept={onAccept}
acceptDialogRef={acceptDialogRef}
/>
Expand All @@ -116,11 +113,6 @@ function OpenGame({game, onClick}) {
"*:py-3",
!disabled && "cursor-pointer *:hover:bg-sky-200 *:hover:text-black",
)
let dimClasses = twJoin(
"pl-1",
"pr-3",
"rounded-r-lg",
)
return (
<div
onClick={disabled ? undefined : (event) => {
Expand All @@ -136,15 +128,17 @@ function OpenGame({game, onClick}) {
className={classes}
key={game.id}>
<div className="pl-3 pr-1 rounded-l-lg">{game.user}</div>
<div ref={dimRef} className={dimClasses}>
<div className="px-1">
{game.dim}x{game.dim}
</div>
<div ref={dimRef} className="pl-1 pr-3 rounded-r-lg">
{game.timesetting}s
</div>
</div>
)
}

function AcceptDialog({onAccept, acceptDialog, acceptDialogRef}) {
let acceptableGame = acceptDialog?.data
function AcceptDialog({onAccept, acceptableGame, acceptDialogRef}) {
let [isFlip, setFlip] = useState(false)
let [handi, setHandi] = useState(1)
let auth = useAuthStore(state => state.auth)
Expand All @@ -161,18 +155,18 @@ function AcceptDialog({onAccept, acceptDialog, acceptDialogRef}) {
left: Math.trunc(acceptableGame?.rect.right || 0) + 16,
}}
className={twJoin(
!acceptDialog && "hidden",
!acceptableGame && "hidden",
"absolute bg-sky-200 px-4 py-3 rounded-lg z-8 flex flex-col",
)}>
<div className="text-black">
<button type="button" className="inline-flex" onClick={() => setFlip(!isFlip)}>
<BabyStone color={isFlip ? "white": "black"} className="pr-2" />
<BabyStone color={isFlip ? "white" : "black"} className="pr-2" />
{acceptableGame?.game.user}
</button>
</div>
<div className="text-black">
<button type="button" className="inline-flex" onClick={() => setFlip(!isFlip)}>
<BabyStone color={isFlip ? "black": "white"} className="pr-2" />
<BabyStone color={isFlip ? "black" : "white"} className="pr-2" />
{auth.name}
</button>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/main/client/src/feature/lobby/lobbyState.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ export function setNewGameOpen(state, el) {
return setOpen(state, el, "newgame")
}

export function getAcceptDialog({stack}) {
export function getAcceptData({stack}) {
if (!stack.length) {
return undefined
}
let result = stack.filter(obj => obj.kind === "accept")
if (!result.length) {
return undefined
}
return result[0]
return result[0].data
}

export function setAcceptDialogOpen(state, el, data) {
Expand Down

0 comments on commit bef5b0e

Please sign in to comment.