@@ -48,7 +48,7 @@ export class FileNode extends React.Component {
48
48
} , 200 ) ;
49
49
}
50
50
51
- getName ( ) {
51
+ get updatedName ( ) {
52
52
return this . state . updatedName ;
53
53
}
54
54
@@ -63,7 +63,7 @@ export class FileNode extends React.Component {
63
63
64
64
handleFileClick ( e ) {
65
65
e . stopPropagation ( ) ;
66
- if ( this . getName ( ) !== 'root' && ! this . isDeleting ) {
66
+ if ( this . updatedName !== 'root' && ! this . isDeleting ) {
67
67
this . props . setSelectedFile ( this . props . id ) ;
68
68
}
69
69
}
@@ -81,9 +81,9 @@ export class FileNode extends React.Component {
81
81
82
82
validateFileName ( ) {
83
83
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 ;
87
87
const hasNoExtension = oldFileExtension && ! newFileExtension ;
88
88
const hasExtensionIfFolder = this . props . fileType === 'folder' && hasPeriod ;
89
89
const notSameExtension = oldFileExtension && newFileExtension
@@ -92,7 +92,9 @@ export class FileNode extends React.Component {
92
92
const hasOnlyExtension = newFileExtension && newFileName === newFileExtension [ 0 ] ;
93
93
if ( hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder ) {
94
94
this . props . updateFileName ( this . props . id , this . originalFileName ) ;
95
+ return ;
95
96
}
97
+ this . commitFileNameChange ( ) ;
96
98
}
97
99
98
100
toggleFileOptions ( e ) {
@@ -118,7 +120,6 @@ export class FileNode extends React.Component {
118
120
119
121
hideEditFileName ( ) {
120
122
this . setState ( { isEditingName : false } ) ;
121
- this . commitFileNameChange ( ) ;
122
123
}
123
124
124
125
renderChild ( childId ) {
@@ -131,8 +132,8 @@ export class FileNode extends React.Component {
131
132
132
133
render ( ) {
133
134
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' ,
136
137
'sidebar__file-item--selected' : this . props . isSelectedFile ,
137
138
'sidebar__file-item--open' : this . state . isOptionsOpen ,
138
139
'sidebar__file-item--editing' : this . state . isEditingName ,
@@ -142,7 +143,7 @@ export class FileNode extends React.Component {
142
143
return (
143
144
< div className = { itemClass } >
144
145
{ ( ( ) => { // eslint-disable-line
145
- if ( this . getName ( ) !== 'root' ) {
146
+ if ( this . updatedName !== 'root' ) {
146
147
return (
147
148
< div className = "file-item__content" onContextMenu = { this . toggleFileOptions } >
148
149
< span className = "file-item__spacer" > </ span >
@@ -171,11 +172,11 @@ export class FileNode extends React.Component {
171
172
</ div >
172
173
) ;
173
174
} ) ( ) }
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 >
175
176
< input
176
177
type = "text"
177
178
className = "sidebar__file-item-input"
178
- value = { this . getName ( ) }
179
+ value = { this . updatedName }
179
180
maxLength = "128"
180
181
onChange = { this . handleFileNameChange }
181
182
ref = { ( element ) => { this . fileNameInput = element ; } }
@@ -241,7 +242,7 @@ export class FileNode extends React.Component {
241
242
< li >
242
243
< button
243
244
onClick = { ( ) => {
244
- this . originalFileName = this . getName ( ) ;
245
+ this . originalFileName = this . updatedName ;
245
246
this . showEditFileName ( ) ;
246
247
setTimeout ( ( ) => this . fileNameInput . focus ( ) , 0 ) ;
247
248
setTimeout ( ( ) => this . hideFileOptions ( ) , 0 ) ;
@@ -256,7 +257,7 @@ export class FileNode extends React.Component {
256
257
< li >
257
258
< button
258
259
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 } ?` ) ) {
260
261
this . isDeleting = true ;
261
262
this . props . resetSelectedFile ( this . props . id ) ;
262
263
setTimeout ( ( ) => this . props . deleteFile ( this . props . id , this . props . parentId ) , 100 ) ;
0 commit comments