@@ -7,14 +7,14 @@ import storage from '../lib/storage';
77import {
88 LoadingStates ,
99 createProject ,
10+ doneCreatingProject ,
11+ doneUpdatingProject ,
1012 getIsCreating ,
1113 getIsShowingProject ,
1214 getIsShowingWithoutId ,
1315 getIsUpdating ,
14- onCreated ,
15- onUpdated ,
16- onError ,
17- saveProject
16+ projectError ,
17+ updateProject
1818} from '../reducers/project-state' ;
1919
2020/**
@@ -33,34 +33,39 @@ const ProjectSaverHOC = function (WrappedComponent) {
3333 this . storeProject ( this . props . reduxProjectId )
3434 . then ( ( ) => {
3535 // there is nothing we expect to find in response that we need to check here
36- this . props . onUpdated ( this . props . loadingState ) ;
36+ this . props . onUpdatedProject ( this . props . loadingState ) ;
3737 } )
3838 . catch ( err => {
3939 // NOTE: should throw up a notice for user
40- this . props . onError ( `Saving the project failed with error: ${ err } ` ) ;
40+ this . props . onProjectError ( `Saving the project failed with error: ${ err } ` ) ;
4141 } ) ;
4242 }
43+ // TODO: distinguish between creating new, remixing, and saving as a copy
4344 if ( this . props . isCreating && ! prevProps . isCreating ) {
4445 this . storeProject ( )
4546 . then ( response => {
46- this . props . onCreated ( response . id . toString ( ) ) ;
47+ this . props . onCreatedProject ( response . id . toString ( ) , this . props . loadingState ) ;
4748 } )
4849 . catch ( err => {
4950 // NOTE: should throw up a notice for user
50- this . props . onError ( `Creating a new project failed with error: ${ err } ` ) ;
51+ this . props . onProjectError ( `Creating a new project failed with error: ${ err } ` ) ;
5152 } ) ;
5253 }
53- // if this is the first time we're able to create this project on the server, create it!
54- const showingCreateable = this . props . canSave && this . props . isShowingWithoutId ;
55- const prevShowingCreateable = prevProps . canSave && prevProps . isShowingWithoutId ;
54+
55+ // check if the project state, and user capabilities, have changed so as to indicate
56+ // that we should create or update project
57+ //
58+ // if we're newly able to create this project on the server, create it!
59+ const showingCreateable = this . props . canCreateNew && this . props . isShowingWithoutId ;
60+ const prevShowingCreateable = prevProps . canCreateNew && prevProps . isShowingWithoutId ;
5661 if ( showingCreateable && ! prevShowingCreateable ) {
57- this . props . createProject ( ) ;
62+ this . props . onCreateProject ( ) ;
5863 } else {
59- // if we're newly * able* to save this project, save it!
64+ // if we're newly able to save this project, save it!
6065 const showingSaveable = this . props . canSave && this . props . isShowingWithId ;
6166 const becameAbleToSave = this . props . canSave && ! prevProps . canSave ;
6267 if ( showingSaveable && becameAbleToSave ) {
63- this . props . saveProject ( ) ;
68+ this . props . onUpdateProject ( ) ;
6469 }
6570 }
6671 }
@@ -89,17 +94,17 @@ const ProjectSaverHOC = function (WrappedComponent) {
8994 render ( ) {
9095 const {
9196 /* eslint-disable no-unused-vars */
92- createProject : createProjectProp ,
9397 isCreating : isCreatingProp ,
9498 isShowingWithId : isShowingWithIdProp ,
9599 isShowingWithoutId : isShowingWithoutIdProp ,
96100 isUpdating : isUpdatingProp ,
97101 loadingState,
98- onCreated : onCreatedProp ,
99- onError : onErrorProp ,
100- onUpdated : onUpdatedProp ,
102+ onCreatedProject : onCreatedProjectProp ,
103+ onCreateProject : onCreateProjectProp ,
104+ onProjectError : onProjectErrorProp ,
105+ onUpdatedProject : onUpdatedProjectProp ,
106+ onUpdateProject : onUpdateProjectProp ,
101107 reduxProjectId,
102- saveProject : saveProjectProp ,
103108 /* eslint-enable no-unused-vars */
104109 ...componentProps
105110 } = this . props ;
@@ -111,18 +116,19 @@ const ProjectSaverHOC = function (WrappedComponent) {
111116 }
112117 }
113118 ProjectSaverComponent . propTypes = {
119+ canCreateNew : PropTypes . bool ,
114120 canSave : PropTypes . bool ,
115- createProject : PropTypes . func ,
116121 isCreating : PropTypes . bool ,
117122 isShowingWithId : PropTypes . bool ,
118123 isShowingWithoutId : PropTypes . bool ,
119124 isUpdating : PropTypes . bool ,
120125 loadingState : PropTypes . oneOf ( LoadingStates ) ,
121- onCreated : PropTypes . func ,
122- onError : PropTypes . func ,
123- onUpdated : PropTypes . func ,
126+ onCreateProject : PropTypes . func ,
127+ onCreatedProject : PropTypes . func ,
128+ onProjectError : PropTypes . func ,
129+ onUpdateProject : PropTypes . func ,
130+ onUpdatedProject : PropTypes . func ,
124131 reduxProjectId : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
125- saveProject : PropTypes . func ,
126132 vm : PropTypes . instanceOf ( VM ) . isRequired
127133 } ;
128134 const mapStateToProps = state => {
@@ -138,11 +144,11 @@ const ProjectSaverHOC = function (WrappedComponent) {
138144 } ;
139145 } ;
140146 const mapDispatchToProps = dispatch => ( {
141- createProject : ( ) => dispatch ( createProject ( ) ) ,
142- onCreated : projectId => dispatch ( onCreated ( projectId ) ) ,
143- onUpdated : ( projectId , loadingState ) => dispatch ( onUpdated ( projectId , loadingState ) ) ,
144- onError : error => dispatch ( onError ( error ) ) ,
145- saveProject : ( ) => dispatch ( saveProject ( ) )
147+ onCreatedProject : ( projectId , loadingState ) => dispatch ( doneCreatingProject ( projectId , loadingState ) ) ,
148+ onCreateProject : ( ) => dispatch ( createProject ( ) ) ,
149+ onProjectError : error => dispatch ( projectError ( error ) ) ,
150+ onUpdateProject : ( ) => dispatch ( updateProject ( ) ) ,
151+ onUpdatedProject : ( projectId , loadingState ) => dispatch ( doneUpdatingProject ( projectId , loadingState ) )
146152 } ) ;
147153 // Allow incoming props to override redux-provided props. Used to mock in tests.
148154 const mergeProps = ( stateProps , dispatchProps , ownProps ) => Object . assign (
0 commit comments