1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-08 12:51:12 +00:00

Add "Download" item to file tree context menu ()

GitOrigin-RevId: af55d782aeaab3acd516a1581d59dd3332109cb8
This commit is contained in:
Alf Eaton 2022-08-12 10:54:32 +01:00 committed by Copybot
parent 0f1163e876
commit ec13ebdc7c
2 changed files with 16 additions and 0 deletions
services/web/frontend/js/features/file-tree

View file

@ -15,6 +15,7 @@ function FileTreeItemMenuItems() {
startCreatingFolder,
startCreatingDocOrFile,
startUploadingDocOrFile,
downloadPath,
} = useFileTreeActionable()
return (
@ -22,6 +23,9 @@ function FileTreeItemMenuItems() {
{canRename ? (
<MenuItem onClick={startRenaming}>{t('rename')}</MenuItem>
) : null}
{downloadPath ? (
<MenuItem href={downloadPath}>{t('download')}</MenuItem>
) : null}
{canDelete ? (
<MenuItem onClick={startDeleting}>{t('delete')}</MenuItem>
) : null}

View file

@ -346,6 +346,17 @@ export function FileTreeActionableProvider({ children }) {
}
}, [])
// build the path for downloading a single file
const downloadPath = useMemo(() => {
if (selectedEntityIds.size === 1) {
const [selectedEntityId] = selectedEntityIds
const selectedEntity = findInTree(fileTreeData, selectedEntityId)
if (selectedEntity?.type === 'fileRef') {
return `/project/${projectId}/file/${selectedEntityId}`
}
}
}, [fileTreeData, projectId, selectedEntityIds])
const value = {
canDelete: selectedEntityIds.size > 0,
canRename: selectedEntityIds.size === 1,
@ -368,6 +379,7 @@ export function FileTreeActionableProvider({ children }) {
cancel,
droppedFiles,
setDroppedFiles,
downloadPath,
}
return (