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