main-layout.tsx 4.8 KB

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