main-layout.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. import { useEditorContext } from '@/shared/context/editor-context'
  18. export const MainLayout: FC = () => {
  19. const { view } = useLayoutContext()
  20. const { isRestrictedTokenMember } = useEditorContext()
  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 chatEnabled = getMeta('ol-chatEnabled') && !isRestrictedTokenMember
  41. const { t } = useTranslation()
  42. return (
  43. <div className="ide-react-main">
  44. <EditorNavigationToolbar />
  45. <div className="ide-react-body">
  46. <PanelGroup
  47. autoSaveId="ide-outer-layout"
  48. direction="horizontal"
  49. className={classNames({
  50. 'ide-panel-group-resizing': sidebarResizing || chatResizing,
  51. })}
  52. >
  53. {/* sidebar */}
  54. <Panel
  55. ref={sidebarPanelRef}
  56. id="panel-sidebar"
  57. order={1}
  58. defaultSize={15}
  59. minSize={5}
  60. maxSize={80}
  61. collapsible
  62. onCollapse={handleSidebarCollapse}
  63. onExpand={handleSidebarExpand}
  64. >
  65. <EditorSidebar />
  66. {view === 'history' && <HistorySidebar />}
  67. </Panel>
  68. <HorizontalResizeHandle
  69. onDoubleClick={toggleSidebar}
  70. resizable={sidebarIsOpen}
  71. onDragging={setSidebarResizing}
  72. hitAreaMargins={{ coarse: 0, fine: 0 }}
  73. >
  74. <HorizontalToggler
  75. id="panel-sidebar"
  76. togglerType="west"
  77. isOpen={sidebarIsOpen}
  78. setIsOpen={setSidebarIsOpen}
  79. tooltipWhenOpen={t('tooltip_hide_filetree')}
  80. tooltipWhenClosed={t('tooltip_show_filetree')}
  81. />
  82. </HorizontalResizeHandle>
  83. <Panel id="panel-outer-main" order={2}>
  84. <PanelGroup autoSaveId="ide-inner-layout" direction="horizontal">
  85. <Panel className="ide-react-panel" id="panel-main" order={1}>
  86. <HistoryContainer />
  87. <EditorAndPdf />
  88. </Panel>
  89. {chatEnabled && (
  90. <>
  91. <HorizontalResizeHandle
  92. onDoubleClick={toggleChat}
  93. resizable={chatIsOpen}
  94. onDragging={setChatResizing}
  95. hitAreaMargins={{ coarse: 0, fine: 0 }}
  96. />
  97. {/* chat */}
  98. <Panel
  99. ref={chatPanelRef}
  100. id="panel-chat"
  101. order={2}
  102. defaultSize={20}
  103. minSize={5}
  104. maxSize={30}
  105. collapsible
  106. onCollapse={handleChatCollapse}
  107. onExpand={handleChatExpand}
  108. >
  109. <ChatPane />
  110. </Panel>
  111. </>
  112. )}
  113. </PanelGroup>
  114. </Panel>
  115. </PanelGroup>
  116. </div>
  117. </div>
  118. )
  119. }