diff --git a/client/constants.js b/client/constants.js index 065b2efb..1bf3571f 100644 --- a/client/constants.js +++ b/client/constants.js @@ -51,7 +51,7 @@ export const DELETE_FILE = 'DELETE_FILE'; export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME'; export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME'; -export const TOGGLE_AUTOSAVE = 'SET_AUTOSAVE'; +export const SET_AUTOSAVE = 'SET_AUTOSAVE'; // eventually, handle errors more specifically and better export const ERROR = 'ERROR'; diff --git a/client/modules/IDE/actions/preferences.js b/client/modules/IDE/actions/preferences.js index 5b5ccc66..5f2e0a7e 100644 --- a/client/modules/IDE/actions/preferences.js +++ b/client/modules/IDE/actions/preferences.js @@ -84,8 +84,19 @@ export function indentWithSpace() { } export function setAutosave(value) { - return { - type: ActionTypes.SET_AUTOSAVE, - value + return (dispatch, getState) => { + dispatch({ + type: ActionTypes.SET_AUTOSAVE, + value + }); + const state = getState(); + if (state.user.authenticated) { + const formParams = { + preferences: { + autosave: value + } + }; + updatePreferences(formParams, dispatch); + } }; } diff --git a/client/modules/IDE/components/Preferences.js b/client/modules/IDE/components/Preferences.js index 2eb6baba..d2a874ad 100644 --- a/client/modules/IDE/components/Preferences.js +++ b/client/modules/IDE/components/Preferences.js @@ -10,6 +10,11 @@ const plusUrl = require('../../../images/plus.svg'); const minusUrl = require('../../../images/minus.svg'); class Preferences extends React.Component { + constructor(props) { + super(props); + this.handleUpdateAutosave = this.handleUpdateAutosave.bind(this); + } + handleUpdateFont(event) { this.props.setFontSize(parseInt(event.target.value, 10)); } @@ -18,6 +23,11 @@ class Preferences extends React.Component { this.props.setIndentation(parseInt(event.target.value, 10)); } + handleUpdateAutosave(event) { + const value = event.target.value === 'true'; + this.props.setAutosave(value); + } + render() { const preferencesContainerClass = classNames({ preferences: true, @@ -106,6 +116,13 @@ class Preferences extends React.Component { +