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-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
|
|
|
|
|
|
|
const { data } = useOpenDirQuery({
|
|
|
|
variables:{
|
|
|
|
path
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2021-07-27 17:24:52 +00:00
|
|
|
<Breadcrum path={path} onDirClick={(newPath)=>{
|
|
|
|
setPath(newPath)
|
|
|
|
}}/>
|
2021-07-26 12:54:22 +00:00
|
|
|
<div>
|
2021-07-27 17:24:52 +00:00
|
|
|
<table className="table table-striped table-hover">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
2021-07-27 19:24:20 +00:00
|
|
|
<th>Size</th>
|
2021-07-27 17:24:52 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2021-07-26 12:54:22 +00:00
|
|
|
|
2021-07-27 17:24:52 +00:00
|
|
|
{ data?.directorys.map(v => (<FileBrowserElement
|
|
|
|
key={v?.id}
|
|
|
|
dir={v}
|
2021-07-28 10:49:35 +00:00
|
|
|
onClick={(dir)=>{
|
|
|
|
setPath(dir.id)
|
2021-07-27 17:24:52 +00:00
|
|
|
}}
|
|
|
|
/>))}
|
|
|
|
|
|
|
|
{ data?.files.map(v => (<FileBrowserElement
|
|
|
|
key={v?.id}
|
|
|
|
file={v}
|
2021-07-28 10:49:35 +00:00
|
|
|
onClick={(file)=>{
|
|
|
|
setOpenFileId(file.id)
|
|
|
|
setShowFile(true)
|
|
|
|
}}
|
2021-07-27 17:24:52 +00:00
|
|
|
/>))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2021-07-26 12:54:22 +00:00
|
|
|
</div>
|
2021-07-28 10:49:35 +00:00
|
|
|
{<FileOpen id={openFileId} show={showFile} onCloseClick={()=>{
|
|
|
|
setShowFile(false)
|
|
|
|
}} />}
|
2021-07-26 12:54:22 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileBrowser
|