Skip to content

Commit e9d06f6

Browse files
committed
[WIP] Updating rename functionality
1 parent cf2ee4f commit e9d06f6

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

client/modules/IDE/actions/project.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,24 @@ export function hideEditProjectName() {
277277
type: ActionTypes.HIDE_EDIT_PROJECT_NAME
278278
};
279279
}
280+
281+
export function changeProjectName(id, newName) {
282+
return (dispatch, getState) => {
283+
console.log('here');
284+
axios.put(`${ROOT_URL}/projects/${id}`, { name: newName }, { withCredentials: true })
285+
.then((response) => {
286+
console.log(response);
287+
dispatch({
288+
type: ActionTypes.SET_PROJECT_NAME,
289+
payload: { id, newName }
290+
});
291+
})
292+
.catch((response) => {
293+
console.log(response);
294+
dispatch({
295+
type: ActionTypes.PROJECT_SAVE_FAIL,
296+
error: response.data
297+
});
298+
});
299+
};
300+
}

client/modules/IDE/components/SketchList.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class SketchList extends React.Component {
3030
this.restoreRenameBoxContent = this.restoreRenameBoxContent.bind(this);
3131
}
3232

33+
componentWillReceiveProps(props) {
34+
this.setState({
35+
renameBoxContent: props.sketches.map(({ name }) => name)
36+
});
37+
}
38+
3339
getSketchesTitle() {
3440
if (this.props.username === this.props.user.username) {
3541
return 'p5.js Web Editor | My sketches';
@@ -118,6 +124,7 @@ class SketchList extends React.Component {
118124
onKeyUp={(e) => {
119125
// Enter pressed
120126
if (e.key === 'Enter') {
127+
this.props.changeProjectName(sketch.id, this.state.renameBoxContent[i]);
121128
this.restoreRenameBoxContent();
122129
this.closeAllRenameBoxes();
123130
}
@@ -272,6 +279,7 @@ SketchList.propTypes = {
272279
cloneProject: PropTypes.func.isRequired,
273280
autosaveProject: PropTypes.func.isRequired,
274281
exportProjectAsZip: PropTypes.func.isRequired,
282+
changeProjectName: PropTypes.func.isRequired
275283
};
276284

277285
SketchList.defaultProps = {

client/modules/IDE/pages/IDEView.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class IDEView extends React.Component {
427427
<Feedback previousPath={this.props.ide.previousPath} />
428428
</Overlay>
429429
}
430+
aa
430431
{ this.props.ide.shareModalVisible &&
431432
<Overlay
432433
title="Share This Sketch"

client/modules/IDE/reducers/projects.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ const sketches = (state = [], action) => {
77
case ActionTypes.DELETE_PROJECT:
88
return state.filter(sketch =>
99
sketch.id !== action.id);
10+
case ActionTypes.SET_PROJECT_NAME: {
11+
// let changedSketch = state.find(sketch => sketch.id === action.payload.id);
12+
// console.log(changedSketch);
13+
// changedSketch
14+
return state.map((sketch) => {
15+
if (sketch.id === action.payload.id) {
16+
return { ...sketch, name: action.payload.newName };
17+
}
18+
return { ...sketch };
19+
});
20+
}
1021
default:
1122
return state;
1223
}

server/controllers/project.controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export function updateProject(req, res) {
6262
res.json({ success: false });
6363
return;
6464
}
65-
if (updatedProject.files.length !== req.body.files.length) {
65+
console.log(updatedProject);
66+
if (req.body.files && updatedProject.files.length !== req.body.files.length) {
6667
const oldFileIds = updatedProject.files.map(file => file.id);
6768
const newFileIds = req.body.files.map(file => file.id);
6869
const staleIds = oldFileIds.filter(id => newFileIds.indexOf(id) === -1);

0 commit comments

Comments
 (0)