main-layout.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { Panel, PanelGroup } from 'react-resizable-panels'
  2. import { FC } from 'react'
  3. import { HorizontalResizeHandle } from '../resize/horizontal-resize-handle'
  4. import classNames from 'classnames'
  5. import { useLayoutContext } from '@/shared/context/layout-context'
  6. import EditorNavigationToolbar from '@/features/ide-react/components/editor-navigation-toolbar'
  7. import ChatPane from '@/features/chat/components/chat-pane'
  8. import { HorizontalToggler } from '@/features/ide-react/components/resize/horizontal-toggler'
  9. import { HistorySidebar } from '@/features/ide-react/components/history-sidebar'
  10. import { HistoryProvider } from '@/features/history/context/history-context'
  11. import History from '@/features/ide-react/components/history'
  12. import EditorSidebar from '@/features/ide-react/components/editor-sidebar'
  13. import { EditorPane } from '@/features/ide-react/components/editor/editor-pane'
  14. import { useTranslation } from 'react-i18next'
  15. import { useSidebarPane } from '@/features/ide-react/hooks/use-sidebar-pane'
  16. import { useChatPane } from '@/features/ide-react/hooks/use-chat-pane'
  17. import { EditorAndPdf } from '@/features/ide-react/components/editor-and-pdf'
  18. import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
  19. export const MainLayout: FC = () => {
  20. const { view } = useLayoutContext()
  21. const {
  22. isOpen: sidebarIsOpen,
  23. setIsOpen: setSidebarIsOpen,
  24. panelRef: sidebarPanelRef,
  25. togglePane: toggleSidebar,
  26. handlePaneExpand: handleSidebarExpand,
  27. handlePaneCollapse: handleSidebarCollapse,
  28. resizing: sidebarResizing,
  29. setResizing: setSidebarResizing,
  30. } = useSidebarPane()
  31. const {
  32. isOpen: chatIsOpen,
  33. panelRef: chatPanelRef,
  34. togglePane: toggleChat,
  35. resizing: chatResizing,
  36. setResizing: setChatResizing,
  37. handlePaneCollapse: handleChatCollapse,
  38. handlePaneExpand: handleChatExpand,
  39. } = useChatPane()
  40. const { currentDocumentId } = useEditorManagerContext()
  41. const { t } = useTranslation()
  42. // keep the editor pane open when a doc is open, even if the history view is open
  43. const editorPane = currentDocumentId ? <EditorPane /> : null
  44. return (
  45. <div className="ide-react-main">
  46. <EditorNavigationToolbar />
  47. <div className="ide-react-body">
  48. <PanelGroup
  49. autoSaveId="ide-outer-layout"
  50. direction="horizontal"
  51. className={classNames({
  52. 'ide-panel-group-resizing': sidebarResizing || chatResizing,
  53. })}
  54. >
  55. {/* sidebar */}
  56. <Panel
  57. ref={sidebarPanelRef}
  58. id="panel-sidebar"
  59. order={1}
  60. defaultSize={15}
  61. minSize={5}
  62. maxSize={80}
  63. collapsible
  64. onCollapse={handleSidebarCollapse}
  65. onExpand={handleSidebarExpand}
  66. >
  67. <EditorSidebar />
  68. {view === 'history' && <HistorySidebar />}
  69. </Panel>
  70. <HorizontalResizeHandle
  71. onDoubleClick={toggleSidebar}
  72. resizable={sidebarIsOpen}
  73. onDragging={setSidebarResizing}
  74. >
  75. <HorizontalToggler
  76. id="panel-sidebar"
  77. togglerType="west"
  78. isOpen={sidebarIsOpen}
  79. setIsOpen={setSidebarIsOpen}
  80. tooltipWhenOpen={t('tooltip_hide_filetree')}
  81. tooltipWhenClosed={t('tooltip_show_filetree')}
  82. />
  83. </HorizontalResizeHandle>
  84. <Panel id="panel-outer-main" order={2}>
  85. <PanelGroup autoSaveId="ide-inner-layout" direction="horizontal">
  86. <Panel className="ide-react-panel" id="panel-main" order={1}>
  87. {view === 'history' ? (
  88. <HistoryProvider>
  89. <History />
  90. </HistoryProvider>
  91. ) : (
  92. <EditorAndPdf editorPane={editorPane} />
  93. )}
  94. </Panel>
  95. <HorizontalResizeHandle
  96. onDoubleClick={toggleChat}
  97. resizable={chatIsOpen}
  98. onDragging={setChatResizing}
  99. />
  100. {/* chat */}
  101. <Panel
  102. ref={chatPanelRef}
  103. id="panel-chat"
  104. order={2}
  105. defaultSize={20}
  106. minSize={5}
  107. maxSize={30}
  108. collapsible
  109. onCollapse={handleChatCollapse}
  110. onExpand={handleChatExpand}
  111. >
  112. <ChatPane />
  113. </Panel>
  114. </PanelGroup>
  115. </Panel>
  116. </PanelGroup>
  117. </div>
  118. </div>
  119. )
  120. }