diff --git a/src/components/FileBrowser.tsx b/src/components/FileBrowser.tsx index 90713e6..8d69035 100644 --- a/src/components/FileBrowser.tsx +++ b/src/components/FileBrowser.tsx @@ -33,6 +33,8 @@ const FileBrowser: React.FC = (props) => { const [srcID,setSrcID] = useState("") const [pasteAction,setPasteAction] = useState() + const [editID,setEditID] = useState("") + const [editEnable,setEditEnable] = useState(false) const [deleteMutation] = useDeleteFileMutation() const [copyMutation] = useCopyMutation() @@ -94,6 +96,10 @@ const FileBrowser: React.FC = (props) => { case Action.FileDownload: downloadFile(genDownloadLink(id)) break + case Action.FileRename: + setEditID(id) + setEditEnable(true) + break default: break } @@ -153,6 +159,18 @@ const FileBrowser: React.FC = (props) => { e.preventDefault() showFileContext(e,{props:{id}}) }} + + editId={editID} + editEnable={editEnable} + + onRenameDone={(id,changed,newName)=>{ + setEditEnable(false) + if (changed){ + console.debug("Changed: ",newName) + }else{ + console.debug("Not changed") + } + }} /> {loading &&
diff --git a/src/components/FileBrowserContextMenu.tsx b/src/components/FileBrowserContextMenu.tsx index e7a31a2..73b8b58 100644 --- a/src/components/FileBrowserContextMenu.tsx +++ b/src/components/FileBrowserContextMenu.tsx @@ -11,6 +11,7 @@ export enum Action { FilePaste, FileMove, FileDownload, + FileRename, DirDelete } @@ -32,6 +33,7 @@ const FileBrowserContextMenu: React.FC = (props) => { Delete Copy Move + Rename Download Paste diff --git a/src/components/FileBrowserElement.tsx b/src/components/FileBrowserElement.tsx index f586108..f5f0937 100644 --- a/src/components/FileBrowserElement.tsx +++ b/src/components/FileBrowserElement.tsx @@ -8,6 +8,9 @@ interface Props { 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) => { @@ -25,7 +28,14 @@ const FileBrowserElement: React.FC = (props) => { onContextMenu={(e)=>props.onContextMenu?.(e)} > - {(props.file) ? :(props.dir)?:<>} + {(props.file) ? :(props.dir)?:<>} ) } diff --git a/src/components/FileBrowserList.tsx b/src/components/FileBrowserList.tsx index cdb57f1..bcac803 100644 --- a/src/components/FileBrowserList.tsx +++ b/src/components/FileBrowserList.tsx @@ -5,10 +5,15 @@ import FileBrowserElement from "./FileBrowserElement" interface Props{ directorys: Directory[] files: File[] - onFileContext?: (event: React.MouseEvent, id: string)=>void + + onFileContext?: (event: React.MouseEvent, id: string)=>void onDirContext?: (event: React.MouseEvent, path: string)=>void onFileClick?: (event: React.MouseEvent,id: string)=>void onDirClick?: (event: React.MouseEvent,path: string)=>void + + editId: string + editEnable: boolean + onRenameDone?: (id: string, changed: boolean, newName: string)=>void } const FileBrowserList: React.FC = (props) => { @@ -31,6 +36,18 @@ const FileBrowserList: React.FC = (props) => { onContextMenu={(e)=>{ props.onDirContext?.(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,"")} />))} { props.files.map(v => ( = (props) => { 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,"")} />))} diff --git a/src/components/FileElement.tsx b/src/components/FileElement.tsx index 4a6b13e..55937d7 100644 --- a/src/components/FileElement.tsx +++ b/src/components/FileElement.tsx @@ -3,16 +3,26 @@ 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 + file: File, + edit: boolean + onRename?: (newName: string)=>void + onCancleRename?: ()=>void } const FileElement: React.FC = (props) => { return ( <> - {props.file.name} + + {dateFormat(props.file.lastModified)}