main-layout.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { Panel, PanelGroup } from 'react-resizable-panels'
  2. import { ElementType, 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. import importOverleafModules from '../../../../../macros/import-overleaf-module.macro'
  19. import LabsUserBetaPromo from '@/features/ide-redesign/components/labs-user-beta-promo'
  20. const mainEditorLayoutModalsModules: Array<{
  21. import: { default: ElementType }
  22. path: string
  23. }> = importOverleafModules('mainEditorLayoutModals')
  24. export const MainLayout: FC = () => {
  25. const { view } = useLayoutContext()
  26. const { isRestrictedTokenMember } = useEditorContext()
  27. const {
  28. isOpen: sidebarIsOpen,
  29. setIsOpen: setSidebarIsOpen,
  30. panelRef: sidebarPanelRef,
  31. togglePane: toggleSidebar,
  32. handlePaneExpand: handleSidebarExpand,
  33. handlePaneCollapse: handleSidebarCollapse,
  34. resizing: sidebarResizing,
  35. setResizing: setSidebarResizing,
  36. } = useSidebarPane()
  37. const {
  38. isOpen: chatIsOpen,
  39. panelRef: chatPanelRef,
  40. togglePane: toggleChat,
  41. resizing: chatResizing,
  42. setResizing: setChatResizing,
  43. handlePaneCollapse: handleChatCollapse,
  44. handlePaneExpand: handleChatExpand,
  45. } = useChatPane()
  46. const chatEnabled =
  47. getMeta('ol-capabilities')?.includes('chat') && !isRestrictedTokenMember
  48. const { t } = useTranslation()
  49. return (
  50. <div className="ide-react-main">
  51. <EditorNavigationToolbar />
  52. <div className="ide-react-body">
  53. <PanelGroup
  54. autoSaveId="ide-outer-layout"
  55. direction="horizontal"
  56. className={classNames({
  57. 'ide-panel-group-resizing': sidebarResizing || chatResizing,
  58. })}
  59. >
  60. {/* sidebar */}
  61. <Panel
  62. ref={sidebarPanelRef}
  63. id="panel-sidebar"
  64. order={1}
  65. defaultSize={15}
  66. minSize={5}
  67. maxSize={80}
  68. collapsible
  69. onCollapse={handleSidebarCollapse}
  70. onExpand={handleSidebarExpand}
  71. >
  72. <EditorSidebar />
  73. {view === 'history' && <HistorySidebar />}
  74. </Panel>
  75. <HorizontalResizeHandle
  76. onDoubleClick={toggleSidebar}
  77. resizable={sidebarIsOpen}
  78. onDragging={setSidebarResizing}
  79. hitAreaMargins={{ coarse: 0, fine: 0 }}
  80. >
  81. <HorizontalToggler
  82. id="panel-sidebar"
  83. togglerType="west"
  84. isOpen={sidebarIsOpen}
  85. setIsOpen={setSidebarIsOpen}
  86. tooltipWhenOpen={t('tooltip_hide_filetree')}
  87. tooltipWhenClosed={t('tooltip_show_filetree')}
  88. />
  89. </HorizontalResizeHandle>
  90. <Panel id="panel-outer-main" order={2}>
  91. <PanelGroup autoSaveId="ide-inner-layout" direction="horizontal">
  92. <Panel className="ide-react-panel" id="panel-main" order={1}>
  93. <HistoryContainer />
  94. <LabsUserBetaPromo />
  95. <EditorAndPdf />
  96. </Panel>
  97. {chatEnabled && (
  98. <>
  99. <HorizontalResizeHandle
  100. onDoubleClick={toggleChat}
  101. resizable={chatIsOpen}
  102. onDragging={setChatResizing}
  103. hitAreaMargins={{ coarse: 0, fine: 0 }}
  104. />
  105. {/* chat */}
  106. <Panel
  107. ref={chatPanelRef}
  108. id="panel-chat"
  109. order={2}
  110. defaultSize={20}
  111. minSize={5}
  112. maxSize={30}
  113. collapsible
  114. onCollapse={handleChatCollapse}
  115. onExpand={handleChatExpand}
  116. >
  117. <ChatPane />
  118. </Panel>
  119. </>
  120. )}
  121. </PanelGroup>
  122. </Panel>
  123. </PanelGroup>
  124. </div>
  125. {mainEditorLayoutModalsModules.map(
  126. ({ import: { default: Component }, path }) => (
  127. <Component key={path} />
  128. )
  129. )}
  130. </div>
  131. )
  132. }