main-layout.tsx 4.8 KB

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