Skip to content

Commit 6561c90

Browse files
committed
wip drag base
1 parent 7e4ece4 commit 6561c90

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ function isLastChildVisible(container) {
124124
}
125125

126126
function SplitPane({messageRef, topElement, bottomElement}) {
127-
let [dragging, setDragging] = useState(false)
127+
let [dragBase, setDragBase] = useState(Number.NaN)
128128
let [splitPos, setSplitPos] = useState(200)
129129
let draggingRef = useRef()
130130
let containerRef = useRef()
131-
draggingRef.current = dragging
131+
draggingRef.current = dragBase
132132
useEffect(() => {
133133
let mousemove = (e) => {
134134
if (!draggingRef.current) {
@@ -141,20 +141,20 @@ function SplitPane({messageRef, topElement, bottomElement}) {
141141
return
142142
}
143143
setSplitPos(getSplitPos(e.clientY, containerRef.current))
144-
setDragging(false)
144+
setDragBase(Number.NaN)
145145
}
146146
window.document.addEventListener("mousemove", mousemove)
147147
window.document.addEventListener("mouseup", mouseup)
148148
return () => {
149149
window.document.removeEventListener("mousemove", mousemove)
150150
window.document.removeEventListener("mouseup", mouseup)
151151
}
152-
}, [draggingRef, setDragging])
152+
}, [draggingRef, setDragBase])
153153
let onMouseDown = useCallback((e) => {
154154
e.preventDefault()
155155
setSplitPos(getSplitPos(e.clientY, containerRef.current))
156-
setDragging(true)
157-
}, [setDragging, setSplitPos])
156+
setDragBase(e.clientY)
157+
}, [setDragBase, setSplitPos])
158158
let topElementHeight = Math.trunc(splitPos)
159159
if (containerRef.current) {
160160
let rect = containerRef.current.getBoundingClientRect()
@@ -174,7 +174,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
174174
}}
175175
className={twJoin(
176176
"grow border-t border-x border-gray-500 bg-gray-900 flex flex-col overflow-y-hidden",
177-
dragging && "cursor-row-resize",
177+
!Number.isNaN(dragBase) && "cursor-row-resize",
178178
)}>
179179
<div
180180
style={{height: topElementHeight + "px"}}
@@ -184,7 +184,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
184184
<SplitBar
185185
container={containerRef.current}
186186
splitPos={splitPos}
187-
dragging={dragging}
187+
dragBase={dragBase}
188188
onMouseDown={onMouseDown} />
189189
<div ref={messageRef} className="px-1 pt-3 pb-1 overflow-y-scroll">
190190
{bottomElement}
@@ -193,7 +193,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
193193
)
194194
}
195195

196-
function SplitBar({splitPos, dragging, onMouseDown, container}) {
196+
function SplitBar({splitPos, dragBase, onMouseDown, container}) {
197197
if (!container) {
198198
return <div />
199199
}
@@ -204,15 +204,15 @@ function SplitBar({splitPos, dragging, onMouseDown, container}) {
204204
let left = rect.left - parentRect.left
205205
return <>
206206
<div
207-
onMouseDown={dragging ? undefined : onMouseDown}
207+
onMouseDown={Number.isNaN(dragBase) ? onMouseDown : undefined}
208208
style={{top: Math.trunc(splitPos - 1) + 0.5, height: 1, width: width, left: left}}
209209
className="absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
210210
<div
211-
onMouseDown={dragging ? undefined : onMouseDown}
211+
onMouseDown={Number.isNaN(dragBase) ? onMouseDown : undefined}
212212
style={{top: Math.trunc(splitPos) + 0.5, height: innerHeight, width: width, left: left}}
213213
className="absolute bg-slate-800 z-20 cursor-row-resize" />
214214
<div
215-
onMouseDown={dragging ? undefined : onMouseDown}
215+
onMouseDown={Number.isNaN(dragBase) ? onMouseDown : undefined}
216216
style={{top: Math.trunc(splitPos + innerHeight) + 0.5, height: 1, width: width, left: left}}
217217
className="absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
218218
</>

0 commit comments

Comments
 (0)