main-layout.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. handleLayout: handleSidebarLayout,
  26. togglePane: toggleSidebar,
  27. handlePaneExpand: handleSidebarExpand,
  28. handlePaneCollapse: handleSidebarCollapse,
  29. resizing: sidebarResizing,
  30. setResizing: setSidebarResizing,
  31. } = useSidebarPane()
  32. const {
  33. isOpen: chatIsOpen,
  34. panelRef: chatPanelRef,
  35. handleLayout: handleChatLayout,
  36. togglePane: toggleChat,
  37. resizing: chatResizing,
  38. setResizing: setChatResizing,
  39. handlePaneCollapse: handleChatCollapse,
  40. handlePaneExpand: handleChatExpand,
  41. } = useChatPane()
  42. const { currentDocumentId } = useEditorManagerContext()
  43. const { t } = useTranslation()
  44. // keep the editor pane open when a doc is open, even if the history view is open
  45. const editorPane = currentDocumentId ? <EditorPane /> : null
  46. return (
  47. <div className="ide-react-main">
  48. <EditorNavigationToolbar />
  49. <div className="ide-react-body">
  50. <PanelGroup
  51. autoSaveId="ide-outer-layout"
  52. direction="horizontal"
  53. onLayout={handleSidebarLayout}
  54. className={classNames({
  55. 'ide-panel-group-resizing': sidebarResizing || chatResizing,
  56. })}
  57. >
  58. {/* sidebar */}
  59. <Panel
  60. ref={sidebarPanelRef}
  61. id="panel-sidebar"
  62. order={1}
  63. defaultSize={10}
  64. minSize={10}
  65. maxSize={30}
  66. collapsible
  67. onCollapse={handleSidebarCollapse}
  68. onExpand={handleSidebarExpand}
  69. >
  70. <EditorSidebar />
  71. {view === 'history' && <HistorySidebar />}
  72. </Panel>
  73. <HorizontalResizeHandle
  74. onDoubleClick={toggleSidebar}
  75. resizable={sidebarIsOpen}
  76. onDragging={setSidebarResizing}
  77. >
  78. <HorizontalToggler
  79. id="panel-sidebar"
  80. togglerType="west"
  81. isOpen={sidebarIsOpen}
  82. setIsOpen={setSidebarIsOpen}
  83. tooltipWhenOpen={t('tooltip_hide_filetree')}
  84. tooltipWhenClosed={t('tooltip_show_filetree')}
  85. />
  86. </HorizontalResizeHandle>
  87. <Panel id="panel-outer-main" order={2}>
  88. <PanelGroup
  89. autoSaveId="ide-inner-layout"
  90. direction="horizontal"
  91. onLayout={handleChatLayout}
  92. >
  93. <Panel className="ide-react-panel" id="panel-main" order={1}>
  94. {view === 'history' ? (
  95. <HistoryProvider>
  96. <History />
  97. </HistoryProvider>
  98. ) : (
  99. <EditorAndPdf editorPane={editorPane} />
  100. )}
  101. </Panel>
  102. <HorizontalResizeHandle
  103. onDoubleClick={toggleChat}
  104. resizable={chatIsOpen}
  105. onDragging={setChatResizing}
  106. />
  107. {/* chat */}
  108. <Panel
  109. ref={chatPanelRef}
  110. id="panel-chat"
  111. order={2}
  112. defaultSize={20}
  113. minSize={10}
  114. maxSize={30}
  115. collapsible
  116. onCollapse={handleChatCollapse}
  117. onExpand={handleChatExpand}
  118. >
  119. <ChatPane />
  120. </Panel>
  121. </PanelGroup>
  122. </Panel>
  123. </PanelGroup>
  124. </div>
  125. </div>
  126. )
  127. }