File tree Expand file tree Collapse file tree 5 files changed +43
-1
lines changed Expand file tree Collapse file tree 5 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -277,3 +277,24 @@ export function hideEditProjectName() {
277
277
type : ActionTypes . HIDE_EDIT_PROJECT_NAME
278
278
} ;
279
279
}
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
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ class SketchList extends React.Component {
30
30
this . restoreRenameBoxContent = this . restoreRenameBoxContent . bind ( this ) ;
31
31
}
32
32
33
+ componentWillReceiveProps ( props ) {
34
+ this . setState ( {
35
+ renameBoxContent : props . sketches . map ( ( { name } ) => name )
36
+ } ) ;
37
+ }
38
+
33
39
getSketchesTitle ( ) {
34
40
if ( this . props . username === this . props . user . username ) {
35
41
return 'p5.js Web Editor | My sketches' ;
@@ -118,6 +124,7 @@ class SketchList extends React.Component {
118
124
onKeyUp = { ( e ) => {
119
125
// Enter pressed
120
126
if ( e . key === 'Enter' ) {
127
+ this . props . changeProjectName ( sketch . id , this . state . renameBoxContent [ i ] ) ;
121
128
this . restoreRenameBoxContent ( ) ;
122
129
this . closeAllRenameBoxes ( ) ;
123
130
}
@@ -272,6 +279,7 @@ SketchList.propTypes = {
272
279
cloneProject : PropTypes . func . isRequired ,
273
280
autosaveProject : PropTypes . func . isRequired ,
274
281
exportProjectAsZip : PropTypes . func . isRequired ,
282
+ changeProjectName : PropTypes . func . isRequired
275
283
} ;
276
284
277
285
SketchList . defaultProps = {
Original file line number Diff line number Diff line change @@ -427,6 +427,7 @@ class IDEView extends React.Component {
427
427
< Feedback previousPath = { this . props . ide . previousPath } />
428
428
</ Overlay >
429
429
}
430
+ aa
430
431
{ this . props . ide . shareModalVisible &&
431
432
< Overlay
432
433
title = "Share This Sketch"
Original file line number Diff line number Diff line change @@ -7,6 +7,17 @@ const sketches = (state = [], action) => {
7
7
case ActionTypes . DELETE_PROJECT :
8
8
return state . filter ( sketch =>
9
9
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
+ }
10
21
default :
11
22
return state ;
12
23
}
Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ export function updateProject(req, res) {
62
62
res . json ( { success : false } ) ;
63
63
return ;
64
64
}
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 ) {
66
67
const oldFileIds = updatedProject . files . map ( file => file . id ) ;
67
68
const newFileIds = req . body . files . map ( file => file . id ) ;
68
69
const staleIds = oldFileIds . filter ( id => newFileIds . indexOf ( id ) === - 1 ) ;
You can’t perform that action at this time.
0 commit comments