🚧 refactor updateFileNmae to thunk, add updatedName param

This commit is contained in:
ghalestrilo 2020-04-07 20:04:00 -03:00
parent 7d05aa78e3
commit 5df76c249a
2 changed files with 11 additions and 7 deletions

View File

@ -135,11 +135,15 @@ export function createFolder(formProps) {
};
}
export function updateFileName(id, name) {
return {
type: ActionTypes.UPDATE_FILE_NAME,
id,
name
export function updateFileName(id, name, updatedName = '') {
return (dispatch) => {
// Notify Changes if necessary
// Update the Filename
dispatch({
type: ActionTypes.UPDATE_FILE_NAME,
id,
name
});
};
}

View File

@ -61,7 +61,7 @@ export class FileNode extends React.Component {
handleFileNameChange(event) {
this.props.updateFileName(this.props.id, event.target.value);
this.props.updateFileName(this.props.id, event.target.value, this.getName());
}
handleKeyPress(event) {
@ -82,7 +82,7 @@ export class FileNode extends React.Component {
const hasEmptyFilename = newFileName === '';
const hasOnlyExtension = newFileExtension && newFileName === newFileExtension[0];
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder) {
this.props.updateFileName(this.props.id, this.originalFileName);
this.props.updateFileName(this.props.id, this.originalFileName, this.getName());
}
}