reset selected file after deleting
This commit is contained in:
parent
3dfed2a11e
commit
cd0dcc9184
3 changed files with 37 additions and 21 deletions
|
@ -157,6 +157,7 @@ export function updateFileName(id, name) {
|
|||
export function deleteFile(id, parentId) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
if (state.project.id) {
|
||||
const deleteConfig = {
|
||||
params: {
|
||||
parentId
|
||||
|
@ -170,10 +171,18 @@ export function deleteFile(id, parentId) {
|
|||
parentId
|
||||
});
|
||||
})
|
||||
.catch(response => dispatch({
|
||||
.catch(response => {
|
||||
dispatch({
|
||||
type: ActionTypes.ERROR,
|
||||
error: response.data
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: ActionTypes.DELETE_FILE,
|
||||
id,
|
||||
parentId
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -37,10 +37,14 @@ export function setSelectedFile(fileId) {
|
|||
};
|
||||
}
|
||||
|
||||
export function resetSelectedFile() {
|
||||
export function resetSelectedFile(previousId) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
setSelectedFile(state.files[1].id);
|
||||
const newId = state.files.find(file => file.name !== 'root' && file.id !== previousId).id;
|
||||
dispatch({
|
||||
type: ActionTypes.SET_SELECTED_FILE,
|
||||
selectedFile: newId
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,10 @@ export class FileNode extends React.Component {
|
|||
|
||||
handleFileClick(e) {
|
||||
e.stopPropagation();
|
||||
if (!this.isDeleting) {
|
||||
this.props.setSelectedFile(this.props.id);
|
||||
}
|
||||
}
|
||||
|
||||
handleFileNameChange(event) {
|
||||
this.props.updateFileName(this.props.id, event.target.value);
|
||||
|
@ -105,8 +107,9 @@ export class FileNode extends React.Component {
|
|||
<a
|
||||
onClick={() => {
|
||||
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
|
||||
this.props.deleteFile(this.props.id, this.props.parentId);
|
||||
this.props.resetSelectedFile();
|
||||
this.isDeleting = true;
|
||||
this.props.resetSelectedFile(this.props.id);
|
||||
setTimeout(() => this.props.deleteFile(this.props.id, this.props.parentId), 0);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue