Skip to content

Commit 2b874e7

Browse files
committed
fix sidebar resize
1 parent 8fd1c42 commit 2b874e7

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

src/main/client/src/component/Chat.jsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ import {
1111
import {
1212
useAuthStore,
1313
} from "src/store.js"
14+
import {
15+
useLayoutStore,
16+
} from "src/layout.js"
1417
import {
1518
StompContext,
1619
tfetch,
1720
doTry,
1821
getRemInPixel,
22+
DELTA,
1923
} from "src/util.js"
2024

21-
export const Chat = ({chatId}) => {
25+
export const Chat = ({page, chatId, className}) => {
2226
let [messages, setMessages] = useState([])
2327
let [users, setUsers] = useState([])
2428
let messageRef = useRef()
@@ -90,6 +94,8 @@ export const Chat = ({chatId}) => {
9094

9195
return <>
9296
<SplitPane
97+
className={className}
98+
page={page}
9399
messageRef={messageRef}
94100
topElement={<>
95101
{users.map(user => (
@@ -123,12 +129,20 @@ function isLastChildVisible(container) {
123129
return lastChildTop < containerBottom
124130
}
125131

126-
function SplitPane({messageRef, topElement, bottomElement}) {
132+
function SplitPane({className, page, messageRef, topElement, bottomElement}) {
133+
let sidebarWidth = useLayoutStore(state => state.sidebarWidth[page])
127134
let [dragOffset, setDragOffset] = useState(Number.NaN)
128135
let [splitPos, setSplitPos] = useState(200)
129136
let splitPosRef = useRef()
130137
splitPosRef.current = splitPos
131138
let containerRef = useRef()
139+
140+
useEffect(() => {
141+
let splitPos = splitPosRef.current
142+
setSplitPos(Math.trunc(splitPos) % 2 ? splitPos + DELTA : splitPos - DELTA)
143+
return undefined
144+
}, [sidebarWidth])
145+
132146
useEffect(() => {
133147
let onMouseMove = (e) => {
134148
if (Number.isNaN(dragOffset)) {
@@ -168,6 +182,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
168182
className={twJoin(
169183
"grow border-t border-x border-gray-500 bg-gray-900 flex flex-col overflow-y-hidden",
170184
!Number.isNaN(dragOffset) && "cursor-row-resize",
185+
className,
171186
)}>
172187
<div
173188
style={{height: topElementHeight + "px"}}
@@ -192,7 +207,7 @@ function SplitBar({splitPos, dragOffset, onMouseDown, container}) {
192207
}
193208
let innerHeight = Math.trunc(getRemInPixel() * 0.5)
194209
let rect = container.getBoundingClientRect()
195-
let parentRect = container.parentNode.getBoundingClientRect()
210+
let parentRect = container.offsetParent.getBoundingClientRect()
196211
let width = rect.width
197212
let left = rect.left - parentRect.left
198213
return <>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function Panel() {
176176
{(result.w > result.b ? "W+" : "B+") + Math.abs(result.b - result.w)}
177177
</div>
178178
)}
179-
<Chat chatId={gameId}/>
179+
<Chat className="mt-1" page="game" chatId={gameId}/>
180180
</>
181181
)
182182
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ function Panel() {
3838
return undefined
3939
}, [auth])
4040
return <>
41-
<Chat chatId="Lobby"/>
41+
<Chat page="lobby" chatId="Lobby" />
4242
</>
4343
}

src/main/client/src/layout.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import {
99
} from "zustand/middleware"
1010
import {
1111
getRemInPixel,
12+
DELTA,
1213
} from "src/util.js"
1314

14-
const TINY = 0.0001220703125
15-
1615
export const useViewStateStore = create((set, get) => ({
1716
zoom: 0,
1817
dragging: false,
@@ -26,7 +25,7 @@ export const useViewStateStore = create((set, get) => ({
2625
if (Math.trunc(zoom)) {
2726
state.zoom = zoom
2827
} else {
29-
state.zoom = get().zoom ? 0 : TINY // force re-render
28+
state.zoom = get().zoom ? 0 : DELTA // force re-render
3029
}
3130
}))
3231
},

src/main/client/src/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export const ANY_REMOVED = REMOVED_W | REMOVED_B
2323

2424
export const COLORS = BLACK | WHITE
2525

26+
// some number that is small, yet big enough for adding to typical pixel values like 100 or 1000
27+
export const DELTA = 0.0001220703125
28+
2629
export async function tfetch(url, options) {
2730
let response
2831
try {

0 commit comments

Comments
 (0)