set preferences when authenticating user
This commit is contained in:
parent
2f581a6a77
commit
d9ea10c4c6
5 changed files with 18 additions and 4 deletions
|
@ -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';
|
||||
|
|
|
@ -21,14 +21,20 @@ class IDEView extends React.Component {
|
|||
const id = this.props.params.project_id;
|
||||
this.props.getProject(id);
|
||||
|
||||
// if autosave is enabled
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
};
|
||||
|
|
|
@ -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' });
|
||||
|
|
Loading…
Reference in a new issue