main-layout.tsx 4.0 KB

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