@@ -9,6 +9,7 @@ import { setUnsavedChanges,
9
9
resetJustOpenedProject ,
10
10
showErrorModal } from './ide' ;
11
11
import { clearState , saveState } from '../../../persistState' ;
12
+ import { redirectToProtocol , protocols } from '../../../components/forceProtocol' ;
12
13
13
14
const ROOT_URL = process . env . API_URL ;
14
15
@@ -28,13 +29,6 @@ export function setProjectName(name) {
28
29
} ;
29
30
}
30
31
31
- export function setServeSecure ( serveSecure ) {
32
- return {
33
- type : ActionTypes . SET_SERVE_SECURE ,
34
- serveSecure
35
- } ;
36
- }
37
-
38
32
export function getProject ( id ) {
39
33
return ( dispatch , getState ) => {
40
34
dispatch ( justOpenedProject ( ) ) ;
@@ -110,39 +104,38 @@ export function saveProject(autosave = false) {
110
104
} ) ;
111
105
}
112
106
} ) ;
113
- browserHistory . push ( `/${ response . data . user . username } /sketches/${ response . data . id } ` ) ;
114
- dispatch ( {
115
- type : ActionTypes . NEW_PROJECT ,
116
- project : response . data ,
117
- owner : response . data . user ,
118
- files : response . data . files
119
- } ) ;
120
- if ( ! autosave ) {
121
- if ( state . preferences . autosave ) {
122
- dispatch ( showToast ( 5500 ) ) ;
123
- dispatch ( setToastText ( 'Project saved.' ) ) ;
124
- setTimeout ( ( ) => dispatch ( setToastText ( 'Autosave enabled.' ) ) , 1500 ) ;
125
- dispatch ( resetJustOpenedProject ( ) ) ;
126
- } else {
127
- dispatch ( showToast ( 1500 ) ) ;
128
- dispatch ( setToastText ( 'Project saved.' ) ) ;
129
- }
130
- }
131
- } )
132
- . catch ( ( response ) => {
133
- if ( response . status === 403 ) {
134
- dispatch ( showErrorModal ( 'staleSession' ) ) ;
135
107
}
136
108
137
109
return axios . post ( `${ ROOT_URL } /projects` , formParams , { withCredentials : true } )
138
110
. then ( ( response ) => {
139
111
dispatch ( setUnsavedChanges ( false ) ) ;
140
112
dispatch ( setProject ( response . data ) ) ;
113
+ browserHistory . push ( `/${ response . data . user . username } /sketches/${ response . data . id } ` ) ;
114
+ dispatch ( {
115
+ type : ActionTypes . NEW_PROJECT ,
116
+ project : response . data ,
117
+ owner : response . data . user ,
118
+ files : response . data . files
119
+ } ) ;
120
+ if ( ! autosave ) {
121
+ if ( state . preferences . autosave ) {
122
+ dispatch ( showToast ( 5500 ) ) ;
123
+ dispatch ( setToastText ( 'Project saved.' ) ) ;
124
+ setTimeout ( ( ) => dispatch ( setToastText ( 'Autosave enabled.' ) ) , 1500 ) ;
125
+ dispatch ( resetJustOpenedProject ( ) ) ;
141
126
} else {
142
- dispatch ( {
143
- type : ActionTypes . PROJECT_SAVE_FAIL ,
144
- error : response . data
127
+ dispatch ( showToast ( 1500 ) ) ;
128
+ dispatch ( setToastText ( 'Project saved.' ) ) ;
145
129
}
130
+ }
131
+ } )
132
+ . catch ( ( response ) => {
133
+ if ( response . status === 403 ) {
134
+ dispatch ( showErrorModal ( 'staleSession' ) ) ;
135
+ } else {
136
+ dispatch ( {
137
+ type : ActionTypes . PROJECT_SAVE_FAIL ,
138
+ error : response . data
146
139
} ) ;
147
140
}
148
141
} ) ;
@@ -257,6 +250,24 @@ export function cloneProject() {
257
250
} ;
258
251
}
259
252
253
+ export function setServeSecure ( serveSecure , { redirect = true } = { } ) {
254
+ return ( dispatch , getState ) => {
255
+ dispatch ( {
256
+ type : ActionTypes . SET_SERVE_SECURE ,
257
+ serveSecure
258
+ } ) ;
259
+
260
+ if ( redirect === true ) {
261
+ dispatch ( saveProject ( false /* autosave */ ) )
262
+ . then (
263
+ ( ) => redirectToProtocol ( serveSecure === true ? protocols . https : protocols . http )
264
+ ) ;
265
+ }
266
+
267
+ return null ;
268
+ } ;
269
+ }
270
+
260
271
export function showEditProjectName ( ) {
261
272
return {
262
273
type : ActionTypes . SHOW_EDIT_PROJECT_NAME
0 commit comments