|
@@ -1,60 +1,20 @@
|
|
|
-import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
|
|
-import TwoColumnMainContent from '@/features/ide-react/components/layout/two-column-main-content'
|
|
|
|
|
-import EditorSidebar from '@/features/ide-react/components/editor-sidebar'
|
|
|
|
|
-import History from '@/features/ide-react/components/history'
|
|
|
|
|
-import { HistoryProvider } from '@/features/history/context/history-context'
|
|
|
|
|
-import { useProjectContext } from '@/shared/context/project-context'
|
|
|
|
|
-import { useLayoutContext } from '@/shared/context/layout-context'
|
|
|
|
|
|
|
+import { FileRef } from '../../../../../types/file-ref'
|
|
|
|
|
+import { BinaryFile } from '@/features/file-view/types/binary-file'
|
|
|
|
|
+import { useSelectFileTreeEntity } from '@/features/ide-react/hooks/use-select-file-tree-entity'
|
|
|
|
|
+import useScopeValue from '@/shared/hooks/use-scope-value'
|
|
|
|
|
+import { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
import {
|
|
import {
|
|
|
FileTreeDeleteHandler,
|
|
FileTreeDeleteHandler,
|
|
|
FileTreeDocumentFindResult,
|
|
FileTreeDocumentFindResult,
|
|
|
FileTreeFileRefFindResult,
|
|
FileTreeFileRefFindResult,
|
|
|
FileTreeFindResult,
|
|
FileTreeFindResult,
|
|
|
} from '@/features/ide-react/types/file-tree'
|
|
} from '@/features/ide-react/types/file-tree'
|
|
|
-import FileView from '@/features/file-view/components/file-view'
|
|
|
|
|
-import { FileRef } from '../../../../../types/file-ref'
|
|
|
|
|
-import { EditorPane } from '@/features/ide-react/components/editor/editor-pane'
|
|
|
|
|
-import EditorAndPdf from '@/features/ide-react/components/editor-and-pdf'
|
|
|
|
|
-import MultipleSelectionPane from '@/features/ide-react/components/editor/multiple-selection-pane'
|
|
|
|
|
-import NoSelectionPane from '@/features/ide-react/components/editor/no-selection-pane'
|
|
|
|
|
|
|
+import { debugConsole } from '@/utils/debugging'
|
|
|
|
|
+import { useProjectContext } from '@/shared/context/project-context'
|
|
|
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
|
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
|
|
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
|
|
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
|
|
|
-import NoOpenDocPane from '@/features/ide-react/components/editor/no-open-doc-pane'
|
|
|
|
|
-import { debugConsole } from '@/utils/debugging'
|
|
|
|
|
-import { HistorySidebar } from '@/features/ide-react/components/history-sidebar'
|
|
|
|
|
-import { BinaryFile } from '@/features/file-view/types/binary-file'
|
|
|
|
|
-import useScopeValue from '@/shared/hooks/use-scope-value'
|
|
|
|
|
-import { useSelectFileTreeEntity } from '@/features/ide-react/hooks/use-select-file-tree-entity'
|
|
|
|
|
-
|
|
|
|
|
-function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
|
|
|
|
- return {
|
|
|
|
|
- _id: fileRef._id,
|
|
|
|
|
- name: fileRef.name,
|
|
|
|
|
- id: fileRef._id,
|
|
|
|
|
- type: 'file',
|
|
|
|
|
- selected: true,
|
|
|
|
|
- linkedFileData: fileRef.linkedFileData,
|
|
|
|
|
- created: fileRef.created ? new Date(fileRef.created) : new Date(),
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// `FileViewHeader`, which is TypeScript, expects a BinaryFile, which has a
|
|
|
|
|
-// `created` property of type `Date`, while `TPRFileViewInfo`, written in JS,
|
|
|
|
|
-// into which `FileViewHeader` passes its BinaryFile, expects a file object with
|
|
|
|
|
-// `created` property of type `string`, which is a mismatch. `TPRFileViewInfo`
|
|
|
|
|
-// is the only one making runtime complaints and it seems that other uses of
|
|
|
|
|
-// `FileViewHeader` pass in a string for `created`, so that's what this function
|
|
|
|
|
-// does too.
|
|
|
|
|
-function fileViewFile(fileRef: FileRef) {
|
|
|
|
|
- return {
|
|
|
|
|
- ...convertFileRefToBinaryFile(fileRef),
|
|
|
|
|
- created: fileRef.created,
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-export function EditorAndSidebar() {
|
|
|
|
|
- const [leftColumnDefaultSize, setLeftColumnDefaultSize] = useState(20)
|
|
|
|
|
- const [leftColumnIsOpen, setLeftColumnIsOpen] = useState(true)
|
|
|
|
|
|
|
+export const useFileTree = () => {
|
|
|
const { rootDocId } = useProjectContext()
|
|
const { rootDocId } = useProjectContext()
|
|
|
const { eventEmitter } = useIdeReactContext()
|
|
const { eventEmitter } = useIdeReactContext()
|
|
|
const {
|
|
const {
|
|
@@ -62,7 +22,6 @@ export function EditorAndSidebar() {
|
|
|
currentDocumentId: openDocId,
|
|
currentDocumentId: openDocId,
|
|
|
openInitialDoc,
|
|
openInitialDoc,
|
|
|
} = useEditorManagerContext()
|
|
} = useEditorManagerContext()
|
|
|
- const { view } = useLayoutContext()
|
|
|
|
|
const { projectJoined } = useIdeReactContext()
|
|
const { projectJoined } = useIdeReactContext()
|
|
|
const { selectEntity } = useSelectFileTreeEntity()
|
|
const { selectEntity } = useSelectFileTreeEntity()
|
|
|
const [, setOpenFile] = useScopeValue<BinaryFile | null>('openFile')
|
|
const [, setOpenFile] = useScopeValue<BinaryFile | null>('openFile')
|
|
@@ -145,93 +104,38 @@ export function EditorAndSidebar() {
|
|
|
}
|
|
}
|
|
|
}, [fileTreeReady, openInitialDoc, projectJoined, rootDocId])
|
|
}, [fileTreeReady, openInitialDoc, projectJoined, rootDocId])
|
|
|
|
|
|
|
|
- // Keep the editor file tree around so that it is available and up to date when restoring a file
|
|
|
|
|
- const editorSidebar = (
|
|
|
|
|
- <EditorSidebar
|
|
|
|
|
- shouldShow={view !== 'history'}
|
|
|
|
|
- onFileTreeInit={handleFileTreeInit}
|
|
|
|
|
- onFileTreeSelect={handleFileTreeSelect}
|
|
|
|
|
- onFileTreeDelete={handleFileTreeDelete}
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- if (view === 'history') {
|
|
|
|
|
- return (
|
|
|
|
|
- <TwoColumnMainContent
|
|
|
|
|
- leftColumnId="editor-left-column"
|
|
|
|
|
- leftColumnContent={
|
|
|
|
|
- <>
|
|
|
|
|
- {editorSidebar}
|
|
|
|
|
- <HistorySidebar />
|
|
|
|
|
- </>
|
|
|
|
|
- }
|
|
|
|
|
- leftColumnDefaultSize={leftColumnDefaultSize}
|
|
|
|
|
- setLeftColumnDefaultSize={setLeftColumnDefaultSize}
|
|
|
|
|
- rightColumnContent={
|
|
|
|
|
- <HistoryProvider>
|
|
|
|
|
- <History />
|
|
|
|
|
- </HistoryProvider>
|
|
|
|
|
- }
|
|
|
|
|
- leftColumnIsOpen={leftColumnIsOpen}
|
|
|
|
|
- setLeftColumnIsOpen={setLeftColumnIsOpen}
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ selectedEntityCount,
|
|
|
|
|
+ openEntity,
|
|
|
|
|
+ openDocId,
|
|
|
|
|
+ handleFileTreeInit,
|
|
|
|
|
+ handleFileTreeSelect,
|
|
|
|
|
+ handleFileTreeDelete,
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- // Always have the editor mounted when not in history view, and hide and
|
|
|
|
|
- // show it as necessary
|
|
|
|
|
- const editorPane = (
|
|
|
|
|
- <EditorPane
|
|
|
|
|
- show={openEntity?.type === 'doc' && selectedEntityCount === 1}
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- let rightColumnContent
|
|
|
|
|
-
|
|
|
|
|
- if (openDocId === undefined) {
|
|
|
|
|
- rightColumnContent = <NoOpenDocPane />
|
|
|
|
|
- } else if (selectedEntityCount === 0) {
|
|
|
|
|
- rightColumnContent = (
|
|
|
|
|
- <>
|
|
|
|
|
- {editorPane}
|
|
|
|
|
- <NoSelectionPane />
|
|
|
|
|
- </>
|
|
|
|
|
- )
|
|
|
|
|
- } else if (selectedEntityCount > 1) {
|
|
|
|
|
- rightColumnContent = (
|
|
|
|
|
- <EditorAndPdf
|
|
|
|
|
- editorContent={
|
|
|
|
|
- <>
|
|
|
|
|
- {editorPane}
|
|
|
|
|
- <MultipleSelectionPane selectedEntityCount={selectedEntityCount} />
|
|
|
|
|
- </>
|
|
|
|
|
- }
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
- } else if (openEntity) {
|
|
|
|
|
- rightColumnContent = (
|
|
|
|
|
- <EditorAndPdf
|
|
|
|
|
- editorContent={
|
|
|
|
|
- <>
|
|
|
|
|
- {editorPane}
|
|
|
|
|
- {openEntity.type !== 'doc' && (
|
|
|
|
|
- <FileView file={fileViewFile(openEntity.entity)} />
|
|
|
|
|
- )}
|
|
|
|
|
- </>
|
|
|
|
|
- }
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
|
|
+function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
|
|
|
|
+ return {
|
|
|
|
|
+ _id: fileRef._id,
|
|
|
|
|
+ name: fileRef.name,
|
|
|
|
|
+ id: fileRef._id,
|
|
|
|
|
+ type: 'file',
|
|
|
|
|
+ selected: true,
|
|
|
|
|
+ linkedFileData: fileRef.linkedFileData,
|
|
|
|
|
+ created: fileRef.created ? new Date(fileRef.created) : new Date(),
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- return (
|
|
|
|
|
- <TwoColumnMainContent
|
|
|
|
|
- leftColumnId="editor-left-column"
|
|
|
|
|
- leftColumnContent={editorSidebar}
|
|
|
|
|
- leftColumnDefaultSize={leftColumnDefaultSize}
|
|
|
|
|
- setLeftColumnDefaultSize={setLeftColumnDefaultSize}
|
|
|
|
|
- rightColumnContent={rightColumnContent}
|
|
|
|
|
- leftColumnIsOpen={leftColumnIsOpen}
|
|
|
|
|
- setLeftColumnIsOpen={setLeftColumnIsOpen}
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
|
|
+// `FileViewHeader`, which is TypeScript, expects a BinaryFile, which has a
|
|
|
|
|
+// `created` property of type `Date`, while `TPRFileViewInfo`, written in JS,
|
|
|
|
|
+// into which `FileViewHeader` passes its BinaryFile, expects a file object with
|
|
|
|
|
+// `created` property of type `string`, which is a mismatch. `TPRFileViewInfo`
|
|
|
|
|
+// is the only one making runtime complaints and it seems that other uses of
|
|
|
|
|
+// `FileViewHeader` pass in a string for `created`, so that's what this function
|
|
|
|
|
+// does too.
|
|
|
|
|
+export function fileViewFile(fileRef: FileRef) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...convertFileRefToBinaryFile(fileRef),
|
|
|
|
|
+ created: fileRef.created,
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|