rename files
This commit is contained in:
parent
cd20f098fa
commit
96e435a976
@ -15,6 +15,7 @@ import FileOpen from "./FileOpen"
|
||||
import FileUploadButton from "./FileUploadButton"
|
||||
import { ReactComponent as Spinner } from "./../assets/spinner.svg"
|
||||
import FileBrowserList from "./FileBrowserList"
|
||||
import pathRename from "../functions/pathRename"
|
||||
|
||||
function uriToPath(pathname:string) {
|
||||
// strip the "/f" from e.g. "/f/dir1/dir2"
|
||||
@ -163,12 +164,16 @@ const FileBrowser: React.FC<RouteComponentProps> = (props) => {
|
||||
editId={editID}
|
||||
editEnable={editEnable}
|
||||
|
||||
onRenameDone={(id,changed,newName)=>{
|
||||
onRenameDone={async (id,changed,newName)=>{
|
||||
setEditEnable(false)
|
||||
if (changed){
|
||||
console.debug("Changed: ",newName)
|
||||
}else{
|
||||
console.debug("Not changed")
|
||||
// TODO: maybe change the name on client so it seems more smooth rather then haveing it refetch
|
||||
// TODO: input check & error handling
|
||||
await moveMutation({variables:{
|
||||
src:id,
|
||||
dest: pathRename(id,newName)
|
||||
}})
|
||||
refetchDir()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
11
src/functions/pathRename.ts
Normal file
11
src/functions/pathRename.ts
Normal file
@ -0,0 +1,11 @@
|
||||
function pathRename(id:string, newFilename: string): string {
|
||||
const isDir = id.endsWith("/")
|
||||
const parts = id.split("/")
|
||||
if (!parts.length)
|
||||
throw new Error("Maleformed id")
|
||||
parts[parts.length - (isDir?2:1)] = newFilename
|
||||
|
||||
return parts.join("/")
|
||||
}
|
||||
|
||||
export default pathRename
|
Loading…
Reference in New Issue
Block a user