Skip to content

Commit b5470ec

Browse files
committed
safety margins for sidebar resize
1 parent 2c7b992 commit b5470ec

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/main/client/src/feature/game/Game.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const Game = () => {
6464
let countingGroup = !gameHasEnded() && counting ? getCountingGroup(board, cursor_x, cursor_y) : undefined
6565
let sidebarWidth = useLayoutStore(state => state.sidebarWidth)
6666
let vw = useLayoutStore(state => state.vw)
67+
let dragging = useLayoutStore(state => state.dragging)
6768

6869
let context = useMemo(() => {
6970
let dim = board.length
@@ -128,6 +129,9 @@ export const Game = () => {
128129
if (gameHasEnded()) {
129130
return
130131
}
132+
if (dragging) {
133+
return
134+
}
131135
if (!board.length) {
132136
return
133137
}
@@ -143,7 +147,7 @@ export const Game = () => {
143147
setCursor_x(-1)
144148
setCursor_y(-1)
145149
}
146-
}, [context, currentPlayer, auth, board.length, counting, gameHasEnded])
150+
}, [context, currentPlayer, auth, board.length, counting, gameHasEnded, dragging])
147151

148152
let onClick = useCallback((e) => {
149153
if (gameHasEnded()) {
@@ -253,9 +257,10 @@ export const Game = () => {
253257

254258
return (
255259
<div
256-
style={{width: (vw - sidebarWidth) + "px"}}>
257-
<div className="grid justify-center mt-8">
258-
<canvas ref={canvasRef}
260+
style={{width: (vw - sidebarWidth) + "px"}}
261+
className="h-full">
262+
<div className="grid h-full">
263+
<canvas className="place-self-center" ref={canvasRef}
259264
onMouseLeave={() => {
260265
setCursor_x(-1)
261266
setCursor_y(-1)

src/main/client/src/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
@tailwind utilities;
44

55
@layer base {
6+
html {
7+
@apply h-full;
8+
}
69
body {
710
@apply bg-stone-800;
811
@apply font-sans;
912
@apply text-stone-100;
13+
@apply h-full;
14+
}
15+
#root {
16+
@apply h-full;
1017
}
1118
}

src/main/client/src/layout.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
export const useLayoutStore = create(
1212
persist(
13-
(set) => ({
13+
(set, get) => ({
1414
dragging: false,
1515
vw: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0),
1616
sidebarWidth: 24 * getPixelRem(),
@@ -20,6 +20,9 @@ export const useLayoutStore = create(
2020
}))
2121
},
2222
setSidebarWidth: (width) => {
23+
let vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
24+
width = Math.max(200, width)
25+
width = Math.min(Math.abs(get().vw - vh), width)
2326
set(produce(state => {
2427
state.sidebarWidth = width
2528
}))

0 commit comments

Comments
 (0)