mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-29 09:40:10 +02:00
make rename work on paths
This commit is contained in:
@@ -108,7 +108,6 @@ function File({
|
|||||||
function dragOverHandler(e) {
|
function dragOverHandler(e) {
|
||||||
if (file.isFolder) {
|
if (file.isFolder) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log(e.target);
|
|
||||||
e.currentTarget.classList.add('is-being-dragged-over');
|
e.currentTarget.classList.add('is-being-dragged-over');
|
||||||
e.currentTarget.style.outline = '1px dashed';
|
e.currentTarget.style.outline = '1px dashed';
|
||||||
}
|
}
|
||||||
@@ -255,7 +254,7 @@ export class SidePane extends Component {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const answer = confirm(`Are you sure you want to delete "${file.name}"?`);
|
const answer = confirm(`Are you sure you want to delete "${file.name}"?`);
|
||||||
if (answer) {
|
if (answer) {
|
||||||
this.props.onRemoveFile(file);
|
this.props.onRemoveFile(file.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renameFile(e) {
|
renameFile(e) {
|
||||||
@@ -268,7 +267,7 @@ export class SidePane extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (newFileName) {
|
if (newFileName) {
|
||||||
this.props.onRenameFile(this.state.fileBeingRenamed.name, newFileName);
|
this.props.onRenameFile(this.state.fileBeingRenamed.path, newFileName);
|
||||||
}
|
}
|
||||||
this.setState({ fileBeingRenamed: null });
|
this.setState({ fileBeingRenamed: null });
|
||||||
}
|
}
|
||||||
|
@@ -1216,26 +1216,23 @@ export default class App extends Component {
|
|||||||
assignFilePaths(currentItem.files);
|
assignFilePaths(currentItem.files);
|
||||||
this.setState({ currentItem });
|
this.setState({ currentItem });
|
||||||
}
|
}
|
||||||
removeFileHandler(file) {
|
removeFileHandler(filePath) {
|
||||||
const currentItem = {
|
const currentItem = {
|
||||||
...this.state.currentItem,
|
...this.state.currentItem,
|
||||||
files: [...this.state.currentItem.files]
|
files: [...this.state.currentItem.files]
|
||||||
};
|
};
|
||||||
removeFileAtPath(currentItem.files, file.path);
|
removeFileAtPath(currentItem.files, filePath);
|
||||||
this.setState({
|
this.setState({
|
||||||
currentItem
|
currentItem
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
renameFileHandler(oldFileName, newFileName) {
|
renameFileHandler(oldFilePath, newFileName) {
|
||||||
let currentItem = {
|
const currentItem = {
|
||||||
...this.state.currentItem,
|
...this.state.currentItem,
|
||||||
files: this.state.currentItem.files.map(file => {
|
files: [...this.state.currentItem.files]
|
||||||
if (file.name === oldFileName) {
|
|
||||||
return { ...file, name: newFileName };
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
const { file } = getFileFromPath(currentItem.files, oldFilePath);
|
||||||
|
file.name = newFileName;
|
||||||
assignFilePaths(currentItem.files);
|
assignFilePaths(currentItem.files);
|
||||||
|
|
||||||
this.setState({ currentItem });
|
this.setState({ currentItem });
|
||||||
@@ -1265,16 +1262,15 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
folderSelectHandler(folder) {
|
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({
|
this.setState({
|
||||||
currentItem: {
|
currentItem
|
||||||
...this.state.currentItem,
|
|
||||||
files: this.state.currentItem.files.map(file => {
|
|
||||||
if (file === folder) {
|
|
||||||
return { ...file, isCollapsed: !folder.isCollapsed };
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user