@@ -48,7 +48,7 @@ export class FileNode extends React.Component {
4848 } , 200 ) ;
4949 }
5050
51- getName ( ) {
51+ get updatedName ( ) {
5252 return this . state . updatedName ;
5353 }
5454
@@ -63,7 +63,7 @@ export class FileNode extends React.Component {
6363
6464 handleFileClick ( e ) {
6565 e . stopPropagation ( ) ;
66- if ( this . getName ( ) !== 'root' && ! this . isDeleting ) {
66+ if ( this . updatedName !== 'root' && ! this . isDeleting ) {
6767 this . props . setSelectedFile ( this . props . id ) ;
6868 }
6969 }
@@ -81,9 +81,9 @@ export class FileNode extends React.Component {
8181
8282 validateFileName ( ) {
8383 const oldFileExtension = this . originalFileName . match ( / \. [ 0 - 9 a - z ] + $ / i) ;
84- const newFileExtension = this . getName ( ) . match ( / \. [ 0 - 9 a - z ] + $ / i) ;
85- const hasPeriod = this . getName ( ) . match ( / \. + / ) ;
86- const newFileName = this . getName ( ) ;
84+ const newFileExtension = this . updatedName . match ( / \. [ 0 - 9 a - z ] + $ / i) ;
85+ const hasPeriod = this . updatedName . match ( / \. + / ) ;
86+ const newFileName = this . updatedName ;
8787 const hasNoExtension = oldFileExtension && ! newFileExtension ;
8888 const hasExtensionIfFolder = this . props . fileType === 'folder' && hasPeriod ;
8989 const notSameExtension = oldFileExtension && newFileExtension
@@ -92,7 +92,9 @@ export class FileNode extends React.Component {
9292 const hasOnlyExtension = newFileExtension && newFileName === newFileExtension [ 0 ] ;
9393 if ( hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder ) {
9494 this . props . updateFileName ( this . props . id , this . originalFileName ) ;
95+ return ;
9596 }
97+ this . commitFileNameChange ( ) ;
9698 }
9799
98100 toggleFileOptions ( e ) {
@@ -118,7 +120,6 @@ export class FileNode extends React.Component {
118120
119121 hideEditFileName ( ) {
120122 this . setState ( { isEditingName : false } ) ;
121- this . commitFileNameChange ( ) ;
122123 }
123124
124125 renderChild ( childId ) {
@@ -131,8 +132,8 @@ export class FileNode extends React.Component {
131132
132133 render ( ) {
133134 const itemClass = classNames ( {
134- 'sidebar__root-item' : this . getName ( ) === 'root' ,
135- 'sidebar__file-item' : this . getName ( ) !== 'root' ,
135+ 'sidebar__root-item' : this . updatedName === 'root' ,
136+ 'sidebar__file-item' : this . updatedName !== 'root' ,
136137 'sidebar__file-item--selected' : this . props . isSelectedFile ,
137138 'sidebar__file-item--open' : this . state . isOptionsOpen ,
138139 'sidebar__file-item--editing' : this . state . isEditingName ,
@@ -142,7 +143,7 @@ export class FileNode extends React.Component {
142143 return (
143144 < div className = { itemClass } >
144145 { ( ( ) => { // eslint-disable-line
145- if ( this . getName ( ) !== 'root' ) {
146+ if ( this . updatedName !== 'root' ) {
146147 return (
147148 < div className = "file-item__content" onContextMenu = { this . toggleFileOptions } >
148149 < span className = "file-item__spacer" > </ span >
@@ -171,11 +172,11 @@ export class FileNode extends React.Component {
171172 </ div >
172173 ) ;
173174 } ) ( ) }
174- < button className = "sidebar__file-item-name" onClick = { this . handleFileClick } > { this . getName ( ) } </ button >
175+ < button className = "sidebar__file-item-name" onClick = { this . handleFileClick } > { this . updatedName } </ button >
175176 < input
176177 type = "text"
177178 className = "sidebar__file-item-input"
178- value = { this . getName ( ) }
179+ value = { this . updatedName }
179180 maxLength = "128"
180181 onChange = { this . handleFileNameChange }
181182 ref = { ( element ) => { this . fileNameInput = element ; } }
@@ -241,7 +242,7 @@ export class FileNode extends React.Component {
241242 < li >
242243 < button
243244 onClick = { ( ) => {
244- this . originalFileName = this . getName ( ) ;
245+ this . originalFileName = this . updatedName ;
245246 this . showEditFileName ( ) ;
246247 setTimeout ( ( ) => this . fileNameInput . focus ( ) , 0 ) ;
247248 setTimeout ( ( ) => this . hideFileOptions ( ) , 0 ) ;
@@ -256,7 +257,7 @@ export class FileNode extends React.Component {
256257 < li >
257258 < button
258259 onClick = { ( ) => {
259- if ( window . confirm ( `Are you sure you want to delete ${ this . getName ( ) } ?` ) ) {
260+ if ( window . confirm ( `Are you sure you want to delete ${ this . updatedName } ?` ) ) {
260261 this . isDeleting = true ;
261262 this . props . resetSelectedFile ( this . props . id ) ;
262263 setTimeout ( ( ) => this . props . deleteFile ( this . props . id , this . props . parentId ) , 100 ) ;
0 commit comments