2020-11-26 14:22:30 +00:00
|
|
|
import React, { useEffect } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import withErrorBoundary from '../../../infrastructure/error-boundary'
|
|
|
|
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 11:55:36 +00:00
|
|
|
import FileTreeModalError from './modals/file-tree-modal-error'
|
2020-11-26 14:22:30 +00: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 { useFileTreeAngularListener } from '../hooks/file-tree-angular-listener'
|
|
|
|
import { useFileTreeSocketListener } from '../hooks/file-tree-socket-listener'
|
|
|
|
|
|
|
|
function FileTreeRoot({
|
|
|
|
projectId,
|
|
|
|
rootFolder,
|
|
|
|
rootDocId,
|
|
|
|
hasWritePermissions,
|
|
|
|
onSelect,
|
2021-01-14 13:57:33 +00:00
|
|
|
onInit,
|
|
|
|
isConnected
|
2020-11-26 14:22:30 +00:00
|
|
|
}) {
|
|
|
|
const isReady = projectId && rootFolder
|
|
|
|
|
2020-12-15 10:23:54 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (isReady) onInit()
|
2021-01-07 14:22:19 +00:00
|
|
|
}, [isReady, onInit])
|
2020-11-26 14:22:30 +00:00
|
|
|
if (!isReady) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeContext
|
|
|
|
projectId={projectId}
|
|
|
|
hasWritePermissions={hasWritePermissions}
|
|
|
|
rootFolder={rootFolder}
|
2021-01-07 14:22:40 +00:00
|
|
|
rootDocId={rootDocId}
|
2020-11-26 14:22:30 +00:00
|
|
|
onSelect={onSelect}
|
|
|
|
>
|
2021-01-14 13:57:33 +00:00
|
|
|
{isConnected ? null : <div className="disconnected-overlay" />}
|
2020-11-26 14:22:30 +00:00
|
|
|
<FileTreeToolbar />
|
|
|
|
<FileTreeContextMenu />
|
|
|
|
<div className="file-tree-inner">
|
|
|
|
<FileTreeRootFolder />
|
|
|
|
</div>
|
|
|
|
<FileTreeModalDelete />
|
|
|
|
<FileTreeModalCreateFolder />
|
2020-12-09 11:55:36 +00:00
|
|
|
<FileTreeModalError />
|
2020-11-26 14:22:30 +00:00
|
|
|
</FileTreeContext>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileTreeRootFolder() {
|
|
|
|
useFileTreeSocketListener()
|
|
|
|
useFileTreeAngularListener()
|
|
|
|
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 14:22:28 +00:00
|
|
|
>
|
|
|
|
<li className="bottom-buffer" />
|
|
|
|
</FileTreeFolderList>
|
2020-11-26 14:22:30 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeRoot.propTypes = {
|
|
|
|
projectId: PropTypes.string,
|
|
|
|
rootFolder: PropTypes.array,
|
|
|
|
rootDocId: PropTypes.string,
|
|
|
|
hasWritePermissions: PropTypes.bool.isRequired,
|
|
|
|
onSelect: PropTypes.func.isRequired,
|
2021-01-14 13:57:33 +00:00
|
|
|
onInit: PropTypes.func.isRequired,
|
|
|
|
isConnected: PropTypes.bool.isRequired
|
2020-11-26 14:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default withErrorBoundary(FileTreeRoot, FileTreeError)
|