From 7d05aa78e351945b474f8dfa9b3ce1492b4c2af4 Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Tue, 7 Apr 2020 19:47:51 -0300 Subject: [PATCH] :construction: create updatedName field in files reducer --- client/modules/IDE/components/FileNode.jsx | 32 ++++++++++++++-------- client/modules/IDE/components/Sidebar.jsx | 1 + client/modules/IDE/reducers/files.js | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/client/modules/IDE/components/FileNode.jsx b/client/modules/IDE/components/FileNode.jsx index f6563706..2979489e 100644 --- a/client/modules/IDE/components/FileNode.jsx +++ b/client/modules/IDE/components/FileNode.jsx @@ -47,13 +47,19 @@ export class FileNode extends React.Component { }, 200); } + getName() { + const { updatedName, name } = this.props; + return updatedName || name; + } + handleFileClick(e) { e.stopPropagation(); - if (this.props.name !== 'root' && !this.isDeleting) { + if (this.getName() !== 'root' && !this.isDeleting) { this.props.setSelectedFile(this.props.id); } } + handleFileNameChange(event) { this.props.updateFileName(this.props.id, event.target.value); } @@ -66,9 +72,9 @@ export class FileNode extends React.Component { validateFileName() { const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i); - const newFileExtension = this.props.name.match(/\.[0-9a-z]+$/i); - const hasPeriod = this.props.name.match(/\.+/); - const newFileName = this.props.name; + const newFileExtension = this.getName().match(/\.[0-9a-z]+$/i); + const hasPeriod = this.getName().match(/\.+/); + const newFileName = this.getName(); const hasNoExtension = oldFileExtension && !newFileExtension; const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod; const notSameExtension = oldFileExtension && newFileExtension @@ -115,8 +121,8 @@ export class FileNode extends React.Component { render() { const itemClass = classNames({ - 'sidebar__root-item': this.props.name === 'root', - 'sidebar__file-item': this.props.name !== 'root', + 'sidebar__root-item': this.getName() === 'root', + 'sidebar__file-item': this.getName() !== 'root', 'sidebar__file-item--selected': this.props.isSelectedFile, 'sidebar__file-item--open': this.state.isOptionsOpen, 'sidebar__file-item--editing': this.state.isEditingName, @@ -126,7 +132,7 @@ export class FileNode extends React.Component { return (
{(() => { // eslint-disable-line - if (this.props.name !== 'root') { + if (this.getName() !== 'root') { return (
@@ -155,11 +161,11 @@ export class FileNode extends React.Component {
); })()} - + { this.fileNameInput = element; }} @@ -225,7 +231,7 @@ export class FileNode extends React.Component {