Skip to content

Commit

Permalink
refactor(common/ResizablePanel): combine functions
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Dec 19, 2023
1 parent 243ed9b commit 6b12f0a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/common/components/ResizablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const ResizablePanel: FC<ResizablePanelProps> = ({
[],
)

const getInitialLeftChildWidth = useCallback(() => getTotalWidth() / 2, [getTotalWidth])
const resetLeftChildWidth = useCallback(
() => setLeftChildWidth(getTotalWidth() / 2),
[getTotalWidth],
)

const getAvailableWidth = useCallback(
() => getTotalWidth() - getOffsetWidth(rightChildRef),
Expand All @@ -56,9 +59,9 @@ const ResizablePanel: FC<ResizablePanelProps> = ({

useLayoutEffect(() => {
if (!isReady) {
setLeftChildWidth(getInitialLeftChildWidth())
resetLeftChildWidth()
}
}, [getInitialLeftChildWidth, isReady])
}, [isReady, resetLeftChildWidth])

useLayoutEffect(() => {
if (leftChildWidth !== undefined) {
Expand All @@ -79,7 +82,7 @@ const ResizablePanel: FC<ResizablePanelProps> = ({

clickCountRef.current += 1
if (clickCountRef.current === 2) {
setLeftChildWidth(getInitialLeftChildWidth())
resetLeftChildWidth()
window.clearTimeout(clickTimeoutIdRef.current)
clickCountRef.current = 0
} else {
Expand Down

0 comments on commit 6b12f0a

Please sign in to comment.