@@ -22,7 +22,6 @@ import {
22
22
getIsShowingWithId ,
23
23
getIsShowingWithoutId ,
24
24
getIsUpdating ,
25
- manualUpdateProject ,
26
25
projectError
27
26
} from '../reducers/project-state' ;
28
27
@@ -51,24 +50,25 @@ const ProjectSaverHOC = function (WrappedComponent) {
51
50
this . createRemixToStorage ( ) ;
52
51
}
53
52
54
- // check if the project state, and user capabilities, have changed so as to indicate
55
- // that we should create or update project
53
+ // see if we should "create" the current project on the server
56
54
//
57
- // if we're newly able to create this project on the server, create it!
58
- const showingCreateable = this . props . canCreateNew && this . props . isShowingWithoutId ;
59
- const prevShowingCreateable = prevProps . canCreateNew && prevProps . isShowingWithoutId ;
60
- const justTriedCreatingNew = prevProps . isCreatingNew ; // don't immediately keep trying
61
- if ( showingCreateable && ! prevShowingCreateable && ! justTriedCreatingNew ) {
55
+ // don't try to create or save immediately after trying to create
56
+ if ( prevProps . isCreatingNew ) return ;
57
+ // if we're newly able to create this project, create it!
58
+ if ( this . isShowingCreatable ( this . props ) && ! this . isShowingCreatable ( prevProps ) ) {
62
59
this . props . onCreateProject ( ) ;
63
- } else {
64
- // if we're newly able to save this project, save it!
65
- const showingSaveable = this . props . canSave && this . props . isShowingWithId ;
66
- const becameAbleToSave = this . props . canSave && ! prevProps . canSave ;
67
- const becameShared = this . props . isShared && ! prevProps . isShared ;
68
- const justTriedUpdating = prevProps . isUpdating ; // don't immediately keep trying
69
- if ( showingSaveable && ! justTriedUpdating && ( becameAbleToSave || becameShared ) ) {
70
- this . props . onAutoUpdateProject ( ) ;
71
- }
60
+ }
61
+
62
+ // see if we should save/update the current project on the server
63
+ //
64
+ // don't try to save immediately after trying to save
65
+ if ( prevProps . isUpdating ) return ;
66
+ // if we're newly able to save this project, save it!
67
+ const showingSaveable = this . props . canSave && this . props . isShowingWithId ;
68
+ const becameAbleToSave = this . props . canSave && ! prevProps . canSave ;
69
+ const becameShared = this . props . isShared && ! prevProps . isShared ;
70
+ if ( showingSaveable && ( becameAbleToSave || becameShared ) ) {
71
+ this . props . onAutoUpdateProject ( ) ;
72
72
}
73
73
}
74
74
componentWillUnmount ( ) {
@@ -77,11 +77,15 @@ const ProjectSaverHOC = function (WrappedComponent) {
77
77
this . updateProjectToStorage ( ) ;
78
78
}
79
79
}
80
+ isShowingCreatable ( props ) {
81
+ return props . canCreateNew && props . isShowingWithoutId ;
82
+ }
80
83
updateProjectToStorage ( ) {
81
84
this . props . onShowSavingAlert ( ) ;
82
85
return this . storeProject ( this . props . reduxProjectId )
83
86
. then ( ( ) => {
84
- // there is nothing we expect to find in response that we need to check here
87
+ // there's an http response object available here, but we don't need to examine
88
+ // it, because there are no values contained in it that we care about
85
89
this . props . onUpdatedProject ( this . props . loadingState ) ;
86
90
this . props . onShowSaveSuccessAlert ( ) ;
87
91
} )
@@ -190,7 +194,6 @@ const ProjectSaverHOC = function (WrappedComponent) {
190
194
onAutoUpdateProject,
191
195
onCreatedProject,
192
196
onCreateProject,
193
- onManualUpdateProject,
194
197
onProjectError,
195
198
onShowAlert,
196
199
onShowCreateSuccessAlert,
@@ -226,7 +229,6 @@ const ProjectSaverHOC = function (WrappedComponent) {
226
229
onAutoUpdateProject : PropTypes . func ,
227
230
onCreateProject : PropTypes . func ,
228
231
onCreatedProject : PropTypes . func ,
229
- onManualUpdateProject : PropTypes . func ,
230
232
onProjectError : PropTypes . func ,
231
233
onShowAlert : PropTypes . func ,
232
234
onShowCreateSuccessAlert : PropTypes . func ,
@@ -258,7 +260,6 @@ const ProjectSaverHOC = function (WrappedComponent) {
258
260
onAutoUpdateProject : ( ) => dispatch ( autoUpdateProject ( ) ) ,
259
261
onCreatedProject : ( projectId , loadingState ) => dispatch ( doneCreatingProject ( projectId , loadingState ) ) ,
260
262
onCreateProject : ( ) => dispatch ( createProject ( ) ) ,
261
- onManualUpdateProject : ( ) => dispatch ( manualUpdateProject ( ) ) ,
262
263
onProjectError : error => dispatch ( projectError ( error ) ) ,
263
264
onShowAlert : alertType => dispatch ( showStandardAlert ( alertType ) ) ,
264
265
onShowCreateSuccessAlert : ( ) => showAlertWithTimeout ( dispatch , 'createSuccess' ) ,
0 commit comments