main-layout.tsx 4.3 KB

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