2023-10-02 09:35:02 +00:00
|
|
|
import { Panel, PanelGroup } from 'react-resizable-panels'
|
2023-12-05 09:34:21 +00:00
|
|
|
import { useState } from 'react'
|
2023-10-02 09:35:02 +00:00
|
|
|
import { HorizontalResizeHandle } from '../resize/horizontal-resize-handle'
|
|
|
|
import useFixedSizeColumn from '@/features/ide-react/hooks/use-fixed-size-column'
|
|
|
|
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
|
2023-11-15 11:55:05 +00:00
|
|
|
import classNames from 'classnames'
|
2023-12-05 09:34:21 +00:00
|
|
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
|
|
|
import EditorNavigationToolbar from '@/features/ide-react/components/editor-navigation-toolbar'
|
|
|
|
import ChatPane from '@/features/chat/components/chat-pane'
|
|
|
|
import { EditorAndSidebar } from '@/features/ide-react/components/editor-and-sidebar'
|
2023-10-02 09:35:02 +00:00
|
|
|
|
|
|
|
const CHAT_DEFAULT_SIZE = 20
|
|
|
|
|
|
|
|
// The main area below the header is split into two: the main content and chat.
|
|
|
|
// The reason for not splitting the left column containing the file tree and
|
|
|
|
// outline here is that the history view has its own file tree, so it is more
|
|
|
|
// convenient to replace the whole of the main content when in history view.
|
2023-12-05 09:34:21 +00:00
|
|
|
export default function MainLayout() {
|
|
|
|
const { chatIsOpen } = useLayoutContext()
|
|
|
|
|
2023-10-02 09:35:02 +00:00
|
|
|
const { fixedPanelRef: chatPanelRef, handleLayout } = useFixedSizeColumn(
|
|
|
|
CHAT_DEFAULT_SIZE,
|
|
|
|
chatIsOpen
|
|
|
|
)
|
|
|
|
|
|
|
|
useCollapsiblePanel(chatIsOpen, chatPanelRef)
|
|
|
|
|
2023-11-15 11:55:05 +00:00
|
|
|
const [resizing, setResizing] = useState(false)
|
|
|
|
|
2023-10-02 09:35:02 +00:00
|
|
|
return (
|
|
|
|
<div className="ide-react-main">
|
2023-12-05 09:34:21 +00:00
|
|
|
<EditorNavigationToolbar />
|
2023-10-02 09:35:02 +00:00
|
|
|
<div className="ide-react-body">
|
|
|
|
<PanelGroup
|
2023-12-05 09:34:21 +00:00
|
|
|
autoSaveId="ide-react-chat-layout"
|
2023-10-02 09:35:02 +00:00
|
|
|
direction="horizontal"
|
|
|
|
onLayout={handleLayout}
|
2023-11-15 11:55:05 +00:00
|
|
|
className={classNames({
|
|
|
|
'ide-react-main-resizing': resizing,
|
|
|
|
})}
|
2023-10-02 09:35:02 +00:00
|
|
|
>
|
|
|
|
<Panel id="main" order={1}>
|
2023-12-05 09:34:21 +00:00
|
|
|
<EditorAndSidebar />
|
2023-10-02 09:35:02 +00:00
|
|
|
</Panel>
|
|
|
|
{chatIsOpen ? (
|
|
|
|
<>
|
2023-11-15 11:55:05 +00:00
|
|
|
<HorizontalResizeHandle onDragging={setResizing} />
|
2023-10-02 09:35:02 +00:00
|
|
|
<Panel
|
|
|
|
ref={chatPanelRef}
|
|
|
|
id="chat"
|
|
|
|
order={2}
|
|
|
|
defaultSize={CHAT_DEFAULT_SIZE}
|
|
|
|
minSize={5}
|
|
|
|
collapsible
|
|
|
|
>
|
2023-12-05 09:34:21 +00:00
|
|
|
<ChatPane />
|
2023-10-02 09:35:02 +00:00
|
|
|
</Panel>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</PanelGroup>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|