download button
This commit is contained in:
parent
37840ece32
commit
6dcd9cf81e
@ -2,6 +2,8 @@ import React from "react"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useContextMenu } from "react-contexify"
|
import { useContextMenu } from "react-contexify"
|
||||||
import { RouteComponentProps } from "react-router-dom"
|
import { RouteComponentProps } from "react-router-dom"
|
||||||
|
import downloadFile from "../functions/downloadFile"
|
||||||
|
import genDownloadLink from "../functions/genDownloadLink"
|
||||||
import normalizeDirPath from "../functions/normalizeDirPath"
|
import normalizeDirPath from "../functions/normalizeDirPath"
|
||||||
import uploadFile from "../functions/uploadFile"
|
import uploadFile from "../functions/uploadFile"
|
||||||
import { useCopyMutation, useCreateDirMutation, useDeleteDirMutation, useDeleteFileMutation, useMoveMutation, useOpenDirQuery } from "../generated/graphql"
|
import { useCopyMutation, useCreateDirMutation, useDeleteDirMutation, useDeleteFileMutation, useMoveMutation, useOpenDirQuery } from "../generated/graphql"
|
||||||
@ -106,6 +108,9 @@ const FileBrowser: React.FC<RouteComponentProps> = (props) => {
|
|||||||
await deleteDirMutation({variables:{path:id}})
|
await deleteDirMutation({variables:{path:id}})
|
||||||
refetchDir()
|
refetchDir()
|
||||||
break
|
break
|
||||||
|
case Action.FileDownload:
|
||||||
|
downloadFile(genDownloadLink(id))
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ export enum Action {
|
|||||||
FileCopy,
|
FileCopy,
|
||||||
FilePaste,
|
FilePaste,
|
||||||
FileMove,
|
FileMove,
|
||||||
|
FileDownload,
|
||||||
DirDelete
|
DirDelete
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ const FileBrowserContextMenu: React.FC<Props> = (props) => {
|
|||||||
<Item onClick={onClick} data={Action.FileDelete} >Delete</Item>
|
<Item onClick={onClick} data={Action.FileDelete} >Delete</Item>
|
||||||
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
|
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
|
||||||
<Item onClick={onClick} data={Action.FileMove} >Move</Item>
|
<Item onClick={onClick} data={Action.FileMove} >Move</Item>
|
||||||
|
<Item onClick={onClick} data={Action.FileDownload} >Download</Item>
|
||||||
<Separator />
|
<Separator />
|
||||||
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
|
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
9
src/functions/downloadFile.ts
Normal file
9
src/functions/downloadFile.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function downloadFile(uri:string): void {
|
||||||
|
const link = document.createElement("a")
|
||||||
|
link.download = ""
|
||||||
|
link.href = uri
|
||||||
|
link.click()
|
||||||
|
link.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
export default downloadFile
|
Loading…
Reference in New Issue
Block a user