download button

This commit is contained in:
Niklas 2021-08-27 21:16:44 +02:00
parent 37840ece32
commit 6dcd9cf81e
3 changed files with 16 additions and 0 deletions

View File

@ -2,6 +2,8 @@ import React from "react"
import { useState } from "react"
import { useContextMenu } from "react-contexify"
import { RouteComponentProps } from "react-router-dom"
import downloadFile from "../functions/downloadFile"
import genDownloadLink from "../functions/genDownloadLink"
import normalizeDirPath from "../functions/normalizeDirPath"
import uploadFile from "../functions/uploadFile"
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}})
refetchDir()
break
case Action.FileDownload:
downloadFile(genDownloadLink(id))
break
default:
break
}

View File

@ -10,6 +10,7 @@ export enum Action {
FileCopy,
FilePaste,
FileMove,
FileDownload,
DirDelete
}
@ -32,6 +33,7 @@ const FileBrowserContextMenu: React.FC<Props> = (props) => {
<Item onClick={onClick} data={Action.FileDelete} >Delete</Item>
<Item onClick={onClick} data={Action.FileCopy} >Copy</Item>
<Item onClick={onClick} data={Action.FileMove} >Move</Item>
<Item onClick={onClick} data={Action.FileDownload} >Download</Item>
<Separator />
<Item onClick={onClick} data={Action.FilePaste} disabled={!props.pasteActive}>Paste</Item>
</Menu>

View 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