mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
[ide-react] Remove useFixedSizeColumn (#16299)
GitOrigin-RevId: 7cee1e153d5ae3d15250097dc87f430f4e799957
This commit is contained in:
parent
5c6b8ec015
commit
6c73a1d38a
4 changed files with 1 additions and 70 deletions
|
@ -24,7 +24,6 @@ export const MainLayout: FC = () => {
|
||||||
isOpen: sidebarIsOpen,
|
isOpen: sidebarIsOpen,
|
||||||
setIsOpen: setSidebarIsOpen,
|
setIsOpen: setSidebarIsOpen,
|
||||||
panelRef: sidebarPanelRef,
|
panelRef: sidebarPanelRef,
|
||||||
handleLayout: handleSidebarLayout,
|
|
||||||
togglePane: toggleSidebar,
|
togglePane: toggleSidebar,
|
||||||
handlePaneExpand: handleSidebarExpand,
|
handlePaneExpand: handleSidebarExpand,
|
||||||
handlePaneCollapse: handleSidebarCollapse,
|
handlePaneCollapse: handleSidebarCollapse,
|
||||||
|
@ -35,7 +34,6 @@ export const MainLayout: FC = () => {
|
||||||
const {
|
const {
|
||||||
isOpen: chatIsOpen,
|
isOpen: chatIsOpen,
|
||||||
panelRef: chatPanelRef,
|
panelRef: chatPanelRef,
|
||||||
handleLayout: handleChatLayout,
|
|
||||||
togglePane: toggleChat,
|
togglePane: toggleChat,
|
||||||
resizing: chatResizing,
|
resizing: chatResizing,
|
||||||
setResizing: setChatResizing,
|
setResizing: setChatResizing,
|
||||||
|
@ -57,7 +55,6 @@ export const MainLayout: FC = () => {
|
||||||
<PanelGroup
|
<PanelGroup
|
||||||
autoSaveId="ide-outer-layout"
|
autoSaveId="ide-outer-layout"
|
||||||
direction="horizontal"
|
direction="horizontal"
|
||||||
onLayout={handleSidebarLayout}
|
|
||||||
className={classNames({
|
className={classNames({
|
||||||
'ide-panel-group-resizing': sidebarResizing || chatResizing,
|
'ide-panel-group-resizing': sidebarResizing || chatResizing,
|
||||||
})}
|
})}
|
||||||
|
@ -94,11 +91,7 @@ export const MainLayout: FC = () => {
|
||||||
</HorizontalResizeHandle>
|
</HorizontalResizeHandle>
|
||||||
|
|
||||||
<Panel id="panel-outer-main" order={2}>
|
<Panel id="panel-outer-main" order={2}>
|
||||||
<PanelGroup
|
<PanelGroup autoSaveId="ide-inner-layout" direction="horizontal">
|
||||||
autoSaveId="ide-inner-layout"
|
|
||||||
direction="horizontal"
|
|
||||||
onLayout={handleChatLayout}
|
|
||||||
>
|
|
||||||
<Panel className="ide-react-panel" id="panel-main" order={1}>
|
<Panel className="ide-react-panel" id="panel-main" order={1}>
|
||||||
{view === 'history' ? (
|
{view === 'history' ? (
|
||||||
<HistoryProvider>
|
<HistoryProvider>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { useLayoutContext } from '@/shared/context/layout-context'
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
||||||
import useFixedSizeColumn from '@/features/ide-react/hooks/use-fixed-size-column'
|
|
||||||
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
|
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
|
||||||
import { useCallback, useRef, useState } from 'react'
|
import { useCallback, useRef, useState } from 'react'
|
||||||
import { ImperativePanelHandle } from 'react-resizable-panels'
|
import { ImperativePanelHandle } from 'react-resizable-panels'
|
||||||
|
@ -9,7 +8,6 @@ export const useChatPane = () => {
|
||||||
const [resizing, setResizing] = useState(false)
|
const [resizing, setResizing] = useState(false)
|
||||||
const panelRef = useRef<ImperativePanelHandle>(null)
|
const panelRef = useRef<ImperativePanelHandle>(null)
|
||||||
|
|
||||||
const handleLayout = useFixedSizeColumn(isOpen, panelRef)
|
|
||||||
useCollapsiblePanel(isOpen, panelRef)
|
useCollapsiblePanel(isOpen, panelRef)
|
||||||
|
|
||||||
const togglePane = useCallback(() => {
|
const togglePane = useCallback(() => {
|
||||||
|
@ -27,7 +25,6 @@ export const useChatPane = () => {
|
||||||
return {
|
return {
|
||||||
isOpen,
|
isOpen,
|
||||||
panelRef,
|
panelRef,
|
||||||
handleLayout,
|
|
||||||
resizing,
|
resizing,
|
||||||
setResizing,
|
setResizing,
|
||||||
togglePane,
|
togglePane,
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
import { RefObject, useCallback, useEffect, useRef, useState } from 'react'
|
|
||||||
import {
|
|
||||||
ImperativePanelHandle,
|
|
||||||
PanelGroupOnLayout,
|
|
||||||
} from 'react-resizable-panels'
|
|
||||||
|
|
||||||
export default function useFixedSizeColumn(
|
|
||||||
isOpen: boolean,
|
|
||||||
fixedPanelRef: RefObject<ImperativePanelHandle>
|
|
||||||
) {
|
|
||||||
const fixedPanelSizeRef = useRef<number>(0)
|
|
||||||
const [initialLayoutDone, setInitialLayoutDone] = useState(false)
|
|
||||||
|
|
||||||
const handleLayout: PanelGroupOnLayout = useCallback(() => {
|
|
||||||
if (fixedPanelRef.current) {
|
|
||||||
fixedPanelSizeRef.current = fixedPanelRef.current.getSize()
|
|
||||||
setInitialLayoutDone(true)
|
|
||||||
}
|
|
||||||
}, [fixedPanelRef])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only start watching for resizes once the initial layout is done,
|
|
||||||
// otherwise we could measure the fixed column while it has zero width and
|
|
||||||
// collapse it
|
|
||||||
if (!initialLayoutDone || !fixedPanelRef.current) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixedPanelElement = document.querySelector(
|
|
||||||
`[data-panel-id="${fixedPanelRef.current.getId()}"]`
|
|
||||||
)
|
|
||||||
if (!fixedPanelElement) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const panelGroupElement = fixedPanelElement.closest('[data-panel-group]')
|
|
||||||
if (!panelGroupElement) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(() => {
|
|
||||||
// when the panel group resizes, set the size of this panel to the previous size, in pixels
|
|
||||||
fixedPanelRef.current?.resize(fixedPanelSizeRef.current)
|
|
||||||
})
|
|
||||||
|
|
||||||
resizeObserver.observe(panelGroupElement)
|
|
||||||
|
|
||||||
return () => resizeObserver.unobserve(panelGroupElement)
|
|
||||||
}, [fixedPanelRef, initialLayoutDone, isOpen])
|
|
||||||
|
|
||||||
return handleLayout
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { useCallback, useRef, useState } from 'react'
|
import { useCallback, useRef, useState } from 'react'
|
||||||
import useFixedSizeColumn from '@/features/ide-react/hooks/use-fixed-size-column'
|
|
||||||
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
|
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
|
||||||
import { ImperativePanelHandle } from 'react-resizable-panels'
|
import { ImperativePanelHandle } from 'react-resizable-panels'
|
||||||
|
|
||||||
|
@ -7,7 +6,6 @@ export const useSidebarPane = () => {
|
||||||
const [isOpen, setIsOpen] = useState(true)
|
const [isOpen, setIsOpen] = useState(true)
|
||||||
const [resizing, setResizing] = useState(false)
|
const [resizing, setResizing] = useState(false)
|
||||||
const panelRef = useRef<ImperativePanelHandle>(null)
|
const panelRef = useRef<ImperativePanelHandle>(null)
|
||||||
const handleLayout = useFixedSizeColumn(isOpen, panelRef)
|
|
||||||
useCollapsiblePanel(isOpen, panelRef)
|
useCollapsiblePanel(isOpen, panelRef)
|
||||||
|
|
||||||
const togglePane = useCallback(() => {
|
const togglePane = useCallback(() => {
|
||||||
|
@ -26,7 +24,6 @@ export const useSidebarPane = () => {
|
||||||
isOpen,
|
isOpen,
|
||||||
setIsOpen,
|
setIsOpen,
|
||||||
panelRef,
|
panelRef,
|
||||||
handleLayout,
|
|
||||||
togglePane,
|
togglePane,
|
||||||
handlePaneExpand,
|
handlePaneExpand,
|
||||||
handlePaneCollapse,
|
handlePaneCollapse,
|
||||||
|
|
Loading…
Reference in a new issue