diff --git a/src/components/SidePane.jsx b/src/components/SidePane.jsx index a15fb3c..4a92327 100644 --- a/src/components/SidePane.jsx +++ b/src/components/SidePane.jsx @@ -108,7 +108,6 @@ function File({ function dragOverHandler(e) { if (file.isFolder) { e.preventDefault(); - console.log(e.target); e.currentTarget.classList.add('is-being-dragged-over'); e.currentTarget.style.outline = '1px dashed'; } @@ -255,7 +254,7 @@ export class SidePane extends Component { e.stopPropagation(); const answer = confirm(`Are you sure you want to delete "${file.name}"?`); if (answer) { - this.props.onRemoveFile(file); + this.props.onRemoveFile(file.path); } } renameFile(e) { @@ -268,7 +267,7 @@ export class SidePane extends Component { return; } if (newFileName) { - this.props.onRenameFile(this.state.fileBeingRenamed.name, newFileName); + this.props.onRenameFile(this.state.fileBeingRenamed.path, newFileName); } this.setState({ fileBeingRenamed: null }); } diff --git a/src/components/app.jsx b/src/components/app.jsx index 227e497..c0fac95 100644 --- a/src/components/app.jsx +++ b/src/components/app.jsx @@ -1216,26 +1216,23 @@ export default class App extends Component { assignFilePaths(currentItem.files); this.setState({ currentItem }); } - removeFileHandler(file) { + removeFileHandler(filePath) { const currentItem = { ...this.state.currentItem, files: [...this.state.currentItem.files] }; - removeFileAtPath(currentItem.files, file.path); + removeFileAtPath(currentItem.files, filePath); this.setState({ currentItem }); } - renameFileHandler(oldFileName, newFileName) { - let currentItem = { + renameFileHandler(oldFilePath, newFileName) { + const currentItem = { ...this.state.currentItem, - files: this.state.currentItem.files.map(file => { - if (file.name === oldFileName) { - return { ...file, name: newFileName }; - } - return file; - }) + files: [...this.state.currentItem.files] }; + const { file } = getFileFromPath(currentItem.files, oldFilePath); + file.name = newFileName; assignFilePaths(currentItem.files); this.setState({ currentItem }); @@ -1265,16 +1262,15 @@ export default class App extends Component { } folderSelectHandler(folder) { + // Following will make the change in the existing currentItem + folder.isCollapsed = !folder.isCollapsed; + + const currentItem = { + ...this.state.currentItem, + files: [...this.state.currentItem.files] + }; this.setState({ - currentItem: { - ...this.state.currentItem, - files: this.state.currentItem.files.map(file => { - if (file === folder) { - return { ...file, isCollapsed: !folder.isCollapsed }; - } - return file; - }) - } + currentItem }); }