1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-29 17:50:09 +02:00

Misc fixes for file explorer.

- Add validation while dropping a file
- Refactor removing file to work on path not reference
- style fixes
This commit is contained in:
Kushagra Gour
2018-10-12 23:53:36 +05:30
parent d3f06ac890
commit 57e41b2f4d
4 changed files with 36 additions and 19 deletions

View File

@@ -26,7 +26,8 @@ import {
linearizeFiles,
assignFilePaths,
getFileFromPath,
removeFileAtPath
removeFileAtPath,
doesFileExistInFolder
} from '../fileUtils';
import { itemService } from '../itemService';
import '../db';
@@ -1215,14 +1216,14 @@ export default class App extends Component {
assignFilePaths(currentItem.files);
this.setState({ currentItem });
}
removeFileHandler(fileToRemove) {
removeFileHandler(file) {
const currentItem = {
...this.state.currentItem,
files: [...this.state.currentItem.files]
};
removeFileAtPath(currentItem.files, file.path);
this.setState({
currentItem: {
...this.state.currentItem,
files: this.state.currentItem.files.filter(
file => file !== fileToRemove
)
}
currentItem
});
}
renameFileHandler(oldFileName, newFileName) {
@@ -1242,11 +1243,18 @@ export default class App extends Component {
fileDropHandler(sourceFilePath, destinationFolder) {
let { currentItem } = this.state;
const { file } = getFileFromPath(currentItem.files, sourceFilePath);
if (doesFileExistInFolder(destinationFolder, file.name)) {
alert(
`File with name "${
file.name
}" already exists in the destination folder.`
);
return;
}
if (file) {
destinationFolder.children.push(file);
removeFileAtPath(currentItem.files, sourceFilePath);
currentItem = {
...currentItem,
files: [...currentItem.files]