main-layout.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Panel, PanelGroup } from 'react-resizable-panels'
  2. import { useState } from 'react'
  3. import { HorizontalResizeHandle } from '../resize/horizontal-resize-handle'
  4. import useFixedSizeColumn from '@/features/ide-react/hooks/use-fixed-size-column'
  5. import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
  6. import classNames from 'classnames'
  7. import { useLayoutContext } from '@/shared/context/layout-context'
  8. import EditorNavigationToolbar from '@/features/ide-react/components/editor-navigation-toolbar'
  9. import ChatPane from '@/features/chat/components/chat-pane'
  10. import { EditorAndSidebar } from '@/features/ide-react/components/editor-and-sidebar'
  11. const CHAT_DEFAULT_SIZE = 20
  12. // The main area below the header is split into two: the main content and chat.
  13. // The reason for not splitting the left column containing the file tree and
  14. // outline here is that the history view has its own file tree, so it is more
  15. // convenient to replace the whole of the main content when in history view.
  16. export default function MainLayout() {
  17. const { chatIsOpen } = useLayoutContext()
  18. const { fixedPanelRef: chatPanelRef, handleLayout } = useFixedSizeColumn(
  19. CHAT_DEFAULT_SIZE,
  20. chatIsOpen
  21. )
  22. useCollapsiblePanel(chatIsOpen, chatPanelRef)
  23. const [resizing, setResizing] = useState(false)
  24. return (
  25. <div className="ide-react-main">
  26. <EditorNavigationToolbar />
  27. <div className="ide-react-body">
  28. <PanelGroup
  29. autoSaveId="ide-react-chat-layout"
  30. direction="horizontal"
  31. onLayout={handleLayout}
  32. className={classNames({
  33. 'ide-react-main-resizing': resizing,
  34. })}
  35. >
  36. <Panel id="main" order={1}>
  37. <EditorAndSidebar />
  38. </Panel>
  39. {chatIsOpen ? (
  40. <>
  41. <HorizontalResizeHandle onDragging={setResizing} />
  42. <Panel
  43. ref={chatPanelRef}
  44. id="chat"
  45. order={2}
  46. defaultSize={CHAT_DEFAULT_SIZE}
  47. minSize={5}
  48. collapsible
  49. >
  50. <ChatPane />
  51. </Panel>
  52. </>
  53. ) : null}
  54. </PanelGroup>
  55. </div>
  56. </div>
  57. )
  58. }