Skip to content

Commit 220ba3c

Browse files
committed
Returns promise from saveProject() action to allow chaining
1 parent 83b3b18 commit 220ba3c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

client/modules/IDE/actions/project.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ export function saveProject(autosave = false) {
7373
return (dispatch, getState) => {
7474
const state = getState();
7575
if (state.user.id && state.project.owner && state.project.owner.id !== state.user.id) {
76-
return;
76+
return Promise.reject();
7777
}
7878
const formParams = Object.assign({}, state.project);
7979
formParams.files = [...state.files];
8080
if (state.project.id) {
81-
axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
81+
return axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
8282
.then((response) => {
8383
dispatch(setUnsavedChanges(false));
8484
console.log(response.data);
@@ -110,11 +110,6 @@ export function saveProject(autosave = false) {
110110
});
111111
}
112112
});
113-
} else {
114-
axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true })
115-
.then((response) => {
116-
dispatch(setUnsavedChanges(false));
117-
dispatch(setProject(response.data));
118113
browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
119114
dispatch({
120115
type: ActionTypes.NEW_PROJECT,
@@ -137,14 +132,20 @@ export function saveProject(autosave = false) {
137132
.catch((response) => {
138133
if (response.status === 403) {
139134
dispatch(showErrorModal('staleSession'));
135+
}
136+
137+
return axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true })
138+
.then((response) => {
139+
dispatch(setUnsavedChanges(false));
140+
dispatch(setProject(response.data));
140141
} else {
141142
dispatch({
142143
type: ActionTypes.PROJECT_SAVE_FAIL,
143144
error: response.data
144-
});
145145
}
146-
});
147-
}
146+
});
147+
}
148+
});
148149
};
149150
}
150151

0 commit comments

Comments
 (0)