diff --git a/client/constants.js b/client/constants.js index 1bf3571f..00061bf1 100644 --- a/client/constants.js +++ b/client/constants.js @@ -52,6 +52,7 @@ export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME'; export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME'; export const SET_AUTOSAVE = 'SET_AUTOSAVE'; +export const SET_PREFERENCES = 'SET_PREFERENCES'; // eventually, handle errors more specifically and better export const ERROR = 'ERROR'; diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js index 473bae42..c6a5bc47 100644 --- a/client/modules/IDE/pages/IDEView.js +++ b/client/modules/IDE/pages/IDEView.js @@ -21,14 +21,20 @@ class IDEView extends React.Component { const id = this.props.params.project_id; this.props.getProject(id); - // if autosave is enabled - this.autosaveInterval = setInterval(this.props.saveProject, 30000); + if (this.props.preferences.autosave) { + this.autosaveInterval = setInterval(this.props.saveProject, 30000); + } } } componentDidUpdate(prevProps) { - if (!this.autosaveInterval && this.props.project.id && !prevProps.project.id) { + if (!this.autosaveInterval && + ((this.props.preferences.autosave && !prevProps.preferences.autosave) || + (this.props.project.id && !prevProps.project.id))) { this.autosaveInterval = setInterval(this.props.saveProject, 30000); + } else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) { + clearInterval(this.autosaveInterval); + this.autosaveInterval = null; } } diff --git a/client/modules/IDE/reducers/preferences.js b/client/modules/IDE/reducers/preferences.js index 7e755ed2..818dde15 100644 --- a/client/modules/IDE/reducers/preferences.js +++ b/client/modules/IDE/reducers/preferences.js @@ -23,6 +23,8 @@ const preferences = (state = initialState, action) => { }); case ActionTypes.SET_AUTOSAVE: return Object.assign({}, state, { autosave: action.value }); + case ActionTypes.SET_PREFERENCES: + return action.preferences; default: return state; } diff --git a/client/modules/User/actions.js b/client/modules/User/actions.js index 1b4ca040..e46cb778 100644 --- a/client/modules/User/actions.js +++ b/client/modules/User/actions.js @@ -46,6 +46,10 @@ export function getUser() { type: ActionTypes.AUTH_USER, user: response.data }); + dispatch({ + type: ActionTypes.SET_PREFERENCES, + preferences: response.data.preferences + }); }) .catch(response => dispatch(authError(response.data.error))); }; diff --git a/server/controllers/session.controller.js b/server/controllers/session.controller.js index f9585c0c..c36c9d51 100644 --- a/server/controllers/session.controller.js +++ b/server/controllers/session.controller.js @@ -21,7 +21,8 @@ export function getSession(req, res) { if (req.user) { return res.json({ email: req.user.email, - username: req.user.username + username: req.user.username, + preferences: req.user.preferences }); } return res.status(404).send({ message: 'Session does not exist' });