Skip to content

Commit 7d05aa7

Browse files
committed
🚧 create updatedName field in files reducer
1 parent a47245b commit 7d05aa7

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

client/modules/IDE/components/FileNode.jsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ export class FileNode extends React.Component {
4747
}, 200);
4848
}
4949

50+
getName() {
51+
const { updatedName, name } = this.props;
52+
return updatedName || name;
53+
}
54+
5055
handleFileClick(e) {
5156
e.stopPropagation();
52-
if (this.props.name !== 'root' && !this.isDeleting) {
57+
if (this.getName() !== 'root' && !this.isDeleting) {
5358
this.props.setSelectedFile(this.props.id);
5459
}
5560
}
5661

62+
5763
handleFileNameChange(event) {
5864
this.props.updateFileName(this.props.id, event.target.value);
5965
}
@@ -66,9 +72,9 @@ export class FileNode extends React.Component {
6672

6773
validateFileName() {
6874
const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i);
69-
const newFileExtension = this.props.name.match(/\.[0-9a-z]+$/i);
70-
const hasPeriod = this.props.name.match(/\.+/);
71-
const newFileName = this.props.name;
75+
const newFileExtension = this.getName().match(/\.[0-9a-z]+$/i);
76+
const hasPeriod = this.getName().match(/\.+/);
77+
const newFileName = this.getName();
7278
const hasNoExtension = oldFileExtension && !newFileExtension;
7379
const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod;
7480
const notSameExtension = oldFileExtension && newFileExtension
@@ -115,8 +121,8 @@ export class FileNode extends React.Component {
115121

116122
render() {
117123
const itemClass = classNames({
118-
'sidebar__root-item': this.props.name === 'root',
119-
'sidebar__file-item': this.props.name !== 'root',
124+
'sidebar__root-item': this.getName() === 'root',
125+
'sidebar__file-item': this.getName() !== 'root',
120126
'sidebar__file-item--selected': this.props.isSelectedFile,
121127
'sidebar__file-item--open': this.state.isOptionsOpen,
122128
'sidebar__file-item--editing': this.state.isEditingName,
@@ -126,7 +132,7 @@ export class FileNode extends React.Component {
126132
return (
127133
<div className={itemClass}>
128134
{(() => { // eslint-disable-line
129-
if (this.props.name !== 'root') {
135+
if (this.getName() !== 'root') {
130136
return (
131137
<div className="file-item__content" onContextMenu={this.toggleFileOptions}>
132138
<span className="file-item__spacer"></span>
@@ -155,11 +161,11 @@ export class FileNode extends React.Component {
155161
</div>
156162
);
157163
})()}
158-
<button className="sidebar__file-item-name" onClick={this.handleFileClick}>{this.props.name}</button>
164+
<button className="sidebar__file-item-name" onClick={this.handleFileClick}>{this.getName()}</button>
159165
<input
160166
type="text"
161167
className="sidebar__file-item-input"
162-
value={this.props.name}
168+
value={this.getName()}
163169
maxLength="128"
164170
onChange={this.handleFileNameChange}
165171
ref={(element) => { this.fileNameInput = element; }}
@@ -225,7 +231,7 @@ export class FileNode extends React.Component {
225231
<li>
226232
<button
227233
onClick={() => {
228-
this.originalFileName = this.props.name;
234+
this.originalFileName = this.getName();
229235
this.showEditFileName();
230236
setTimeout(() => this.fileNameInput.focus(), 0);
231237
setTimeout(() => this.hideFileOptions(), 0);
@@ -240,7 +246,7 @@ export class FileNode extends React.Component {
240246
<li>
241247
<button
242248
onClick={() => {
243-
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
249+
if (window.confirm(`Are you sure you want to delete ${this.getName()}?`)) {
244250
this.isDeleting = true;
245251
this.props.resetSelectedFile(this.props.id);
246252
setTimeout(() => this.props.deleteFile(this.props.id, this.props.parentId), 100);
@@ -278,6 +284,7 @@ FileNode.propTypes = {
278284
parentId: PropTypes.string,
279285
children: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
280286
name: PropTypes.string.isRequired,
287+
updatedName: PropTypes.string,
281288
fileType: PropTypes.string.isRequired,
282289
isSelectedFile: PropTypes.bool,
283290
isFolderClosed: PropTypes.bool,
@@ -295,7 +302,8 @@ FileNode.propTypes = {
295302
FileNode.defaultProps = {
296303
parentId: '0',
297304
isSelectedFile: false,
298-
isFolderClosed: false
305+
isFolderClosed: false,
306+
updatedName: '',
299307
};
300308

301309
function mapStateToProps(state, ownProps) {

client/modules/IDE/components/Sidebar.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class Sidebar extends React.Component {
141141
Sidebar.propTypes = {
142142
files: PropTypes.arrayOf(PropTypes.shape({
143143
name: PropTypes.string.isRequired,
144+
updatedName: PropTypes.string,
144145
id: PropTypes.string.isRequired
145146
})).isRequired,
146147
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, { name: action.name });
166+
return Object.assign({}, file, { updatedName: action.name });
167167
});
168168
case ActionTypes.DELETE_FILE:
169169
{

0 commit comments

Comments
 (0)