diff --git a/src/components/DirectoryElement.tsx b/src/components/DirectoryElement.tsx deleted file mode 100644 index 593700a..0000000 --- a/src/components/DirectoryElement.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from "react" -import { Directory } from "../generated/graphql" -import { MdFolderOpen } from "react-icons/md" - -interface Props { - dir: Directory -} - -const DirectoryElement: React.FC = (props) => { - return ( - <> - - {props.dir.name} - - - - - - - ) -} - -export default DirectoryElement diff --git a/src/components/FileBrowserElement.tsx b/src/components/FileBrowserElement.tsx deleted file mode 100644 index f5f0937..0000000 --- a/src/components/FileBrowserElement.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import React from "react" -import { Directory, File } from "../generated/graphql" -import DirectoryComponent from "./DirectoryElement" -import FileElement from "./FileElement" - -interface Props { - file?: File - dir?: Directory - onClick?: (event: React.MouseEvent ,data: File | Directory) => void - onContextMenu?: (e:React.MouseEvent) => void - edit: boolean - onRename?: (newName: string)=>void - onCancleRename?: ()=>void -} - -const FileBrowserElement: React.FC = (props) => { - return ( - { - if(props.file){ - props.onClick?.(e,props.file) - }else if(props.dir){ - props.onClick?.(e,props.dir) - } - }} - - onContextMenu={(e)=>props.onContextMenu?.(e)} - - > - {(props.file) ? :(props.dir)?:<>} - - ) -} - -export default FileBrowserElement diff --git a/src/components/FileBrowserList.tsx b/src/components/FileBrowserList.tsx index 3893d9e..680de01 100644 --- a/src/components/FileBrowserList.tsx +++ b/src/components/FileBrowserList.tsx @@ -1,7 +1,12 @@ import React from "react" +import { FaRegFileAlt } from "react-icons/fa" +import { MdFolderOpen } from "react-icons/md" +import dateFormat from "../functions/dateFomat" +import sizeToReadable from "../functions/sizeToReadable" import { Directory, File } from "../generated/graphql" import ObjID from "../types/ObjID" -import FileBrowserElement from "./FileBrowserElement" +import Renameable from "./Renameable" +import Table, { Data, Row } from "./Table" interface Props{ directorys: Directory[] @@ -17,65 +22,59 @@ interface Props{ onRenameDone?: (id: ObjID, changed: boolean, newName: string)=>void } -const FileBrowserList: React.FC = (props) => { - return <> - - - - - - - - - - { props.directorys.map(v => ({ - props.onDirClick?.(e,dir.id) - }} - onContextMenu={(e)=>{ - props.onDirContext?.(e,v.id) - }} +const FileBrowserList: React.FC = ({ + files,directorys,onDirClick,onDirContext,onFileClick,onFileContext,onRenameDone,editId,editEnable +}) => { - edit={props.editEnable && (v.id === props.editId)} + const tableData: Data = { + headers: [ + {name: "Name"}, + {name: "Last Modified"}, + {name: "Size"} + ], + body:[ + ...directorys.map((e):Row=>{return { + cells:[ + { + name:e.name || "", + component:
+ + {e.name != newName?onRenameDone?.(e.id,true,newName):onRenameDone?.(e.id,false,newName)}} + onCancleRename={()=>onRenameDone?.(e.id,false,"")} + /> +
+ }], + data: e, + onClick: ((e,data)=>onDirClick?.(e,data.id)), + onContextMenu: ((e,data)=>onDirContext?.(e,data.id)) + }}), + ...files.map((e):Row=>{return { + cells:[ + { + name:e.name || "", + component:
+ + {e.name != newName?onRenameDone?.(e.id,true,newName):onRenameDone?.(e.id,false,newName)}} + onCancleRename={()=>onRenameDone?.(e.id,false,"")} + /> +
+ }, + {name:dateFormat(e.lastModified)},{name:sizeToReadable(e.size)}], + data: e, + onClick: ((e,data)=>onFileClick?.(e,data.id)), + onContextMenu: ((e,data)=>onFileContext?.(e,data.id)) + }}), + ], + + } - onRename={(newName)=>{ - if (v.name != newName){ - props.onRenameDone?.(v.id,true,newName) - }else{ - props.onRenameDone?.(v.id,false,newName) - } - }} - - onCancleRename={()=>props.onRenameDone?.(v.id,false,"")} - />))} - - { props.files.map(v => ({ - props.onFileClick?.(e,file.id) - }} - onContextMenu={(e)=>{ - props.onFileContext?.(e,v.id) - }} - - edit={props.editEnable && (v.id === props.editId)} - - onRename={(newName)=>{ - if (v.name != newName){ - props.onRenameDone?.(v.id,true,newName) - }else{ - props.onRenameDone?.(v.id,false,newName) - } - }} - - onCancleRename={()=>props.onRenameDone?.(v.id,false,"")} - />))} -
-
NameLast ModifiedSize
- + return } export default FileBrowserList diff --git a/src/components/FileElement.tsx b/src/components/FileElement.tsx deleted file mode 100644 index 55937d7..0000000 --- a/src/components/FileElement.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import React from "react" -import { File } from "../generated/graphql" -import sizeToReadable from "../functions/sizeToReadable" -import dateFormat from "../functions/dateFomat" -import { FaRegFileAlt } from "react-icons/fa" -import Renameable from "./Renameable" - -interface Props { - file: File, - edit: boolean - onRename?: (newName: string)=>void - onCancleRename?: ()=>void -} - -const FileElement: React.FC = (props) => { - return ( - <> - - - - - - ) -} - -export default FileElement
- - - - {dateFormat(props.file.lastModified)} - - {sizeToReadable(props.file.size)} -