2020-11-26 09:22:30 -05:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import { FileTreeMainProvider } from '../contexts/file-tree-main'
|
|
|
|
import { FileTreeActionableProvider } from '../contexts/file-tree-actionable'
|
|
|
|
import { FileTreeMutableProvider } from '../contexts/file-tree-mutable'
|
|
|
|
import { FileTreeSelectableProvider } from '../contexts/file-tree-selectable'
|
|
|
|
import { FileTreeDraggableProvider } from '../contexts/file-tree-draggable'
|
|
|
|
|
|
|
|
// renders all the contexts needed for the file tree:
|
|
|
|
// FileTreeMain: generic store
|
|
|
|
// FileTreeActionable: global UI state for actions (rename, delete, etc.)
|
|
|
|
// FileTreeMutable: provides entities mutation operations
|
|
|
|
// FileTreeSelectable: handles selection and multi-selection
|
|
|
|
function FileTreeContext({
|
|
|
|
projectId,
|
|
|
|
rootFolder,
|
|
|
|
hasWritePermissions,
|
2021-01-07 09:22:40 -05:00
|
|
|
rootDocId,
|
2020-11-26 09:22:30 -05:00
|
|
|
onSelect,
|
|
|
|
children
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<FileTreeMainProvider
|
|
|
|
projectId={projectId}
|
|
|
|
hasWritePermissions={hasWritePermissions}
|
|
|
|
>
|
|
|
|
<FileTreeActionableProvider hasWritePermissions={hasWritePermissions}>
|
|
|
|
<FileTreeMutableProvider rootFolder={rootFolder}>
|
|
|
|
<FileTreeSelectableProvider
|
|
|
|
hasWritePermissions={hasWritePermissions}
|
2021-01-07 09:22:40 -05:00
|
|
|
rootDocId={rootDocId}
|
2020-11-26 09:22:30 -05:00
|
|
|
onSelect={onSelect}
|
|
|
|
>
|
|
|
|
<FileTreeDraggableProvider>{children}</FileTreeDraggableProvider>
|
|
|
|
</FileTreeSelectableProvider>
|
|
|
|
</FileTreeMutableProvider>
|
|
|
|
</FileTreeActionableProvider>
|
|
|
|
</FileTreeMainProvider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
FileTreeContext.propTypes = {
|
|
|
|
projectId: PropTypes.string.isRequired,
|
|
|
|
rootFolder: PropTypes.array.isRequired,
|
|
|
|
hasWritePermissions: PropTypes.bool.isRequired,
|
2021-01-07 09:22:40 -05:00
|
|
|
rootDocId: PropTypes.string,
|
2020-11-26 09:22:30 -05:00
|
|
|
onSelect: PropTypes.func.isRequired,
|
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
|
|
|
PropTypes.node
|
|
|
|
]).isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeContext
|