s3browser-frontend/src/components/FileBrowser.tsx

76 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-07-26 12:54:22 +00:00
import React from "react"
import { useState } from "react"
import { useOpenDirQuery } from "../generated/graphql"
2021-07-27 17:24:52 +00:00
import Breadcrum from "./Breadcrum"
2021-08-01 19:42:26 +00:00
import DragAndDrop from "./DragAndDrop"
2021-07-26 12:54:22 +00:00
import FileBrowserElement from "./FileBrowserElement"
2021-07-28 10:49:35 +00:00
import FileOpen from "./FileOpen"
2021-07-26 12:54:22 +00:00
const FileBrowser: React.FC = () => {
const [path,setPath] = useState("/")
2021-07-28 10:49:35 +00:00
const [openFileId, setOpenFileId] = useState("")
const [showFile, setShowFile] = useState(false)
2021-07-26 12:54:22 +00:00
2021-07-30 20:54:36 +00:00
const { data, loading } = useOpenDirQuery({
2021-07-26 12:54:22 +00:00
variables:{
path
}
})
2021-08-01 19:42:26 +00:00
function handleDrop(files:FileList) {
for (let i = 0; i < files.length; i++) {
const file = files[i]
console.debug(file) // TODO
}
}
2021-07-26 12:54:22 +00:00
return (
<div>
2021-08-01 19:42:26 +00:00
<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>
2021-07-26 12:54:22 +00:00
2021-08-01 19:42:26 +00:00
{ 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)
}} />}
</DragAndDrop>
2021-07-26 12:54:22 +00:00
</div>
)
}
export default FileBrowser