added drag and drop to file browser

This commit is contained in:
Djeeberjr 2021-08-01 21:42:26 +02:00
parent 483ffb58ca
commit 713a96efc5

View File

@ -2,6 +2,7 @@ import React from "react"
import { useState } from "react"
import { useOpenDirQuery } from "../generated/graphql"
import Breadcrum from "./Breadcrum"
import DragAndDrop from "./DragAndDrop"
import FileBrowserElement from "./FileBrowserElement"
import FileOpen from "./FileOpen"
@ -16,46 +17,57 @@ const FileBrowser: React.FC = () => {
}
})
function handleDrop(files:FileList) {
for (let i = 0; i < files.length; i++) {
const file = files[i]
console.debug(file) // TODO
}
}
return (
<div>
<Breadcrum path={path} onDirClick={(newPath)=>{
setPath(newPath)
}}/>
<div>
{loading &&
<div className="loading loading-lg"></div> // TODO: center
}
<table className="table table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<DragAndDrop
handleDrop={handleDrop}
>
<Breadcrum path={path} onDirClick={(newPath)=>{
setPath(newPath)
}}/>
<div>
{loading &&
<div className="loading loading-lg"></div> // TODO: center
}
<table className="table table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Size</th>
</tr>
</thead>
<tbody>
{ data?.directorys.map(v => (<FileBrowserElement
key={v?.id}
dir={v}
onClick={(dir)=>{
setPath(dir.id)
}}
/>))}
{ data?.directorys.map(v => (<FileBrowserElement
key={v?.id}
dir={v}
onClick={(dir)=>{
setPath(dir.id)
}}
/>))}
{ data?.files.map(v => (<FileBrowserElement
key={v?.id}
file={v}
onClick={(file)=>{
setOpenFileId(file.id)
setShowFile(true)
}}
/>))}
</tbody>
</table>
</div>
{<FileOpen id={openFileId} show={showFile} onCloseClick={()=>{
setShowFile(false)
}} />}
{ data?.files.map(v => (<FileBrowserElement
key={v?.id}
file={v}
onClick={(file)=>{
setOpenFileId(file.id)
setShowFile(true)
}}
/>))}
</tbody>
</table>
</div>
{<FileOpen id={openFileId} show={showFile} onCloseClick={()=>{
setShowFile(false)
}} />}
</DragAndDrop>
</div>
)
}