Skip to content

Commit ddec332

Browse files
committed
👌 undoing changes, fixing call duplication on FileNode#updateFilename
1 parent 1b083fe commit ddec332

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

client/modules/IDE/actions/project.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ export function saveProject(selectedFile = null, autosave = false) {
132132
return Promise.reject();
133133
}
134134
const formParams = Object.assign({}, state.project);
135-
formParams.files = [...state.files.map(file => ({ ...file, name: file.updatedName || file.name }))];
136-
formParams.files.forEach((file) => { delete file.updatedName; });
135+
formParams.files = [...state.files];
137136

138137
if (selectedFile) {
139138
const fileToUpdate = formParams.files.find(file => file.id === selectedFile.id);

client/modules/IDE/components/FileNode.jsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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-9a-z]+$/i);
84-
const newFileExtension = this.getName().match(/\.[0-9a-z]+$/i);
85-
const hasPeriod = this.getName().match(/\.+/);
86-
const newFileName = this.getName();
84+
const newFileExtension = this.updatedName.match(/\.[0-9a-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);

client/modules/IDE/components/Sidebar.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ class Sidebar extends React.Component {
141141
Sidebar.propTypes = {
142142
files: PropTypes.arrayOf(PropTypes.shape({
143143
name: PropTypes.string.isRequired,
144-
updatedName: PropTypes.string,
145144
id: PropTypes.string.isRequired
146145
})).isRequired,
147146
setSelectedFile: PropTypes.func.isRequired,

client/modules/IDE/reducers/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const files = (state, action) => {
163163
return file;
164164
}
165165

166-
return Object.assign({}, file, { updatedName: action.name });
166+
return Object.assign({}, file, { name: action.name });
167167
});
168168
case ActionTypes.DELETE_FILE:
169169
{

0 commit comments

Comments
 (0)