🚧 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) { export function updateFileName(id, name, updatedName = '') {
return { return (dispatch) => {
type: ActionTypes.UPDATE_FILE_NAME, // Notify Changes if necessary
id, // Update the Filename
name dispatch({
type: ActionTypes.UPDATE_FILE_NAME,
id,
name
});
}; };
} }

View File

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