2020-11-26 09:22:30 -05:00
|
|
|
import React, { useEffect } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import withErrorBoundary from '../../../infrastructure/error-boundary'
|
2022-01-10 10:46:46 -05:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
2020-11-26 09:22:30 -05:00
|
|
|
import FileTreeContext from './file-tree-context'
|
|
|
|
import FileTreeDraggablePreviewLayer from './file-tree-draggable-preview-layer'
|
|
|
|
import FileTreeFolderList from './file-tree-folder-list'
|
|
|
|
import FileTreeToolbar from './file-tree-toolbar'
|
|
|
|
import FileTreeModalDelete from './modals/file-tree-modal-delete'
|
|
|
|
import FileTreeModalCreateFolder from './modals/file-tree-modal-create-folder'
|
2020-12-09 06:55:36 -05:00
|
|
|
import FileTreeModalError from './modals/file-tree-modal-error'
|
2020-11-26 09:22:30 -05:00
|
|
|
import FileTreeContextMenu from './file-tree-context-menu'
|
|
|
|
import FileTreeError from './file-tree-error'
|
|
|
|
|
|
|
|
import { useFileTreeMutable } from '../contexts/file-tree-mutable'
|
|
|
|
import { useDroppable } from '../contexts/file-tree-draggable'
|
|
|
|
|
|
|
|
import { useFileTreeSocketListener } from '../hooks/file-tree-socket-listener'
|
2021-03-18 05:52:36 -04:00
|
|
|
import FileTreeModalCreateFile from './modals/file-tree-modal-create-file'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-06-21 06:02:38 -04:00
|
|
|
const FileTreeRoot = React.memo(function FileTreeRoot({
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders,
|
|
|
|
reindexReferences,
|
|
|
|
setRefProviderEnabled,
|
|
|
|
setStartedFreeTrial,
|
2020-11-26 09:22:30 -05:00
|
|
|
onSelect,
|
2021-01-14 08:57:33 -05:00
|
|
|
onInit,
|
2021-04-27 03:52:58 -04:00
|
|
|
isConnected,
|
2020-11-26 09:22:30 -05:00
|
|
|
}) {
|
2022-01-10 10:46:46 -05:00
|
|
|
const { _id: projectId, rootFolder } = useProjectContext(
|
|
|
|
projectContextPropTypes
|
|
|
|
)
|
2020-11-26 09:22:30 -05:00
|
|
|
const isReady = projectId && rootFolder
|
|
|
|
|
2020-12-15 05:23:54 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (isReady) onInit()
|
2021-01-07 09:22:19 -05:00
|
|
|
}, [isReady, onInit])
|
2020-11-26 09:22:30 -05:00
|
|
|
if (!isReady) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeContext
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders={refProviders}
|
|
|
|
setRefProviderEnabled={setRefProviderEnabled}
|
|
|
|
setStartedFreeTrial={setStartedFreeTrial}
|
|
|
|
reindexReferences={reindexReferences}
|
2020-11-26 09:22:30 -05:00
|
|
|
onSelect={onSelect}
|
|
|
|
>
|
2021-01-14 08:57:33 -05:00
|
|
|
{isConnected ? null : <div className="disconnected-overlay" />}
|
2020-11-26 09:22:30 -05:00
|
|
|
<FileTreeToolbar />
|
|
|
|
<FileTreeContextMenu />
|
|
|
|
<div className="file-tree-inner">
|
|
|
|
<FileTreeRootFolder />
|
|
|
|
</div>
|
|
|
|
<FileTreeModalDelete />
|
2021-04-29 05:11:00 -04:00
|
|
|
<FileTreeModalCreateFile />
|
2020-11-26 09:22:30 -05:00
|
|
|
<FileTreeModalCreateFolder />
|
2020-12-09 06:55:36 -05:00
|
|
|
<FileTreeModalError />
|
2020-11-26 09:22:30 -05:00
|
|
|
</FileTreeContext>
|
|
|
|
)
|
2021-06-21 06:02:38 -04:00
|
|
|
})
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
function FileTreeRootFolder() {
|
|
|
|
useFileTreeSocketListener()
|
|
|
|
const { fileTreeData } = useFileTreeMutable()
|
|
|
|
|
|
|
|
const { isOver, dropRef } = useDroppable(fileTreeData._id)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<FileTreeDraggablePreviewLayer isOver={isOver} />
|
|
|
|
<FileTreeFolderList
|
|
|
|
folders={fileTreeData.folders}
|
|
|
|
docs={fileTreeData.docs}
|
|
|
|
files={fileTreeData.fileRefs}
|
|
|
|
classes={{ root: 'file-tree-list' }}
|
|
|
|
dropRef={dropRef}
|
|
|
|
isOver={isOver}
|
2021-01-07 09:22:28 -05:00
|
|
|
>
|
|
|
|
<li className="bottom-buffer" />
|
|
|
|
</FileTreeFolderList>
|
2020-11-26 09:22:30 -05:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeRoot.propTypes = {
|
|
|
|
onSelect: PropTypes.func.isRequired,
|
2021-01-14 08:57:33 -05:00
|
|
|
onInit: PropTypes.func.isRequired,
|
2021-03-18 05:52:36 -04:00
|
|
|
isConnected: PropTypes.bool.isRequired,
|
|
|
|
setRefProviderEnabled: PropTypes.func.isRequired,
|
|
|
|
setStartedFreeTrial: PropTypes.func.isRequired,
|
|
|
|
reindexReferences: PropTypes.func.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
refProviders: PropTypes.object.isRequired,
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
|
2022-01-10 10:46:46 -05:00
|
|
|
const projectContextPropTypes = {
|
|
|
|
_id: PropTypes.string.isRequired,
|
|
|
|
rootFolder: PropTypes.array.isRequired,
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
export default withErrorBoundary(FileTreeRoot, FileTreeError)
|