diff --git a/src/components/FileBrowser.tsx b/src/components/FileBrowser.tsx index e1889ed..0355bf4 100644 --- a/src/components/FileBrowser.tsx +++ b/src/components/FileBrowser.tsx @@ -1,5 +1,6 @@ import React from "react" import { useState } from "react" +import uploadFile from "../functions/uploadFile" import { useOpenDirQuery } from "../generated/graphql" import Breadcrum from "./Breadcrum" import DragAndDrop from "./DragAndDrop" @@ -17,17 +18,22 @@ const FileBrowser: React.FC = () => { } }) - function handleDrop(files:FileList) { + async function handleDrop(files:FileList) { + const wait: Promise[] = [] for (let i = 0; i < files.length; i++) { const file = files[i] - console.debug(file) // TODO + wait.push(uploadFile(file, path + file.name)) } + + await Promise.all(wait) } return (
{ + await handleDrop(files) + }} > { setPath(newPath) diff --git a/src/functions/uploadFile.ts b/src/functions/uploadFile.ts new file mode 100644 index 0000000..c3b49fb --- /dev/null +++ b/src/functions/uploadFile.ts @@ -0,0 +1,17 @@ +async function uploadFile(file:File,id: string): Promise { + + console.debug(file) + + + const res = await fetch(`/api/file?${new URLSearchParams({id:id}).toString()}`,{ + method: "POST", + headers: { + "Content-Type": file.type + }, + body: file + }) + + return res.status == 200 +} + +export default uploadFile