* add status check * rename variables and remove unnecessary dependencies * set unsavedchange when error happens * set unsavedchange when error happens
This commit is contained in:
parent
074e654b64
commit
3a0139340c
1 changed files with 10 additions and 3 deletions
|
@ -2,6 +2,7 @@ import { browserHistory } from 'react-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import objectID from 'bson-objectid';
|
import objectID from 'bson-objectid';
|
||||||
import each from 'async/each';
|
import each from 'async/each';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
import * as ActionTypes from '../../../constants';
|
import * as ActionTypes from '../../../constants';
|
||||||
import { showToast, setToastText } from './toast';
|
import { showToast, setToastText } from './toast';
|
||||||
import { setUnsavedChanges,
|
import { setUnsavedChanges,
|
||||||
|
@ -81,9 +82,15 @@ export function saveProject(autosave = false) {
|
||||||
if (state.project.id) {
|
if (state.project.id) {
|
||||||
return axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
|
return axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
const currentState = getState();
|
||||||
|
const savedProject = Object.assign({}, response.data);
|
||||||
|
if (!isEqual(currentState.files, response.data.files)) {
|
||||||
|
savedProject.files = currentState.files;
|
||||||
|
dispatch(setUnsavedChanges(true));
|
||||||
|
} else {
|
||||||
dispatch(setUnsavedChanges(false));
|
dispatch(setUnsavedChanges(false));
|
||||||
console.log(response.data);
|
}
|
||||||
dispatch(setProject(response.data));
|
dispatch(setProject(savedProject));
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionTypes.PROJECT_SAVE_SUCCESS
|
type: ActionTypes.PROJECT_SAVE_SUCCESS
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue