diff --git a/app/soapbox/actions/settings.js b/app/soapbox/actions/settings.js index f7508807c..4a50909fa 100644 --- a/app/soapbox/actions/settings.js +++ b/app/soapbox/actions/settings.js @@ -168,6 +168,18 @@ export const getSettings = createSelector([ .mergeDeep(settings); }); +export function changeSettingImmediate(path, value) { + return dispatch => { + dispatch({ + type: SETTING_CHANGE, + path, + value, + }); + + dispatch(saveSettingsImmediate()); + }; +} + export function changeSetting(path, value) { return dispatch => { dispatch({ @@ -180,23 +192,29 @@ export function changeSetting(path, value) { }; } +export function saveSettingsImmediate() { + return (dispatch, getState) => { + if (!isLoggedIn(getState)) return; + + const state = getState(); + if (getSettings(state).getIn(['saved'])) return; + + const data = state.get('settings').delete('saved').toJS(); + + dispatch(patchMe({ + pleroma_settings_store: { + [FE_NAME]: data, + }, + })).then(response => { + dispatch({ type: SETTING_SAVE }); + }).catch(error => { + dispatch(showAlertForError(error)); + }); + }; +} + const debouncedSave = debounce((dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - const state = getState(); - if (getSettings(state).getIn(['saved'])) return; - - const data = state.get('settings').delete('saved').toJS(); - - dispatch(patchMe({ - pleroma_settings_store: { - [FE_NAME]: data, - }, - })).then(response => { - dispatch({ type: SETTING_SAVE }); - }).catch(error => { - dispatch(showAlertForError(error)); - }); + dispatch(saveSettingsImmediate()); }, 5000, { trailing: true }); export function saveSettings() { diff --git a/app/soapbox/features/developers/developers_challenge.js b/app/soapbox/features/developers/developers_challenge.js index 6ad79c7de..37078604f 100644 --- a/app/soapbox/features/developers/developers_challenge.js +++ b/app/soapbox/features/developers/developers_challenge.js @@ -3,7 +3,7 @@ import React from 'react'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { connect } from 'react-redux'; -import { changeSetting } from 'soapbox/actions/settings'; +import { changeSettingImmediate } from 'soapbox/actions/settings'; import snackbar from 'soapbox/actions/snackbar'; import { SimpleForm, TextInput } from 'soapbox/features/forms'; @@ -38,8 +38,8 @@ class DevelopersChallenge extends React.Component { const { intl, dispatch } = this.props; const { answer } = this.state; - if (answer === 'buzzfizz') { - dispatch(changeSetting(['isDeveloper'], true)); + if (answer === 'boxsoap') { + dispatch(changeSettingImmediate(['isDeveloper'], true)); dispatch(snackbar.success(intl.formatMessage(messages.success))); } else { dispatch(snackbar.error(intl.formatMessage(messages.fail))); @@ -49,8 +49,8 @@ class DevelopersChallenge extends React.Component { render() { const { intl } = this.props; - const challenge = `function fizzbuzz() { - return 'fizz|buzz'.split('|').reverse().join(''); + const challenge = `function soapbox() { + return 'soap|box'.split('|').reverse().join(''); }`; return ( @@ -60,7 +60,7 @@ class DevelopersChallenge extends React.Component { fizzbuzz() }} + values={{ function: soapbox() }} />
               {challenge}
diff --git a/app/soapbox/features/developers/developers_menu.js b/app/soapbox/features/developers/developers_menu.js
index 3dda4bd76..a0031497e 100644
--- a/app/soapbox/features/developers/developers_menu.js
+++ b/app/soapbox/features/developers/developers_menu.js
@@ -4,7 +4,7 @@ import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
 import { connect } from 'react-redux';
 import { Link } from 'react-router-dom';
 
-import { changeSetting } from 'soapbox/actions/settings';
+import { changeSettingImmediate } from 'soapbox/actions/settings';
 import snackbar from 'soapbox/actions/snackbar';
 import Icon from 'soapbox/components/icon';
 
@@ -31,7 +31,7 @@ class DevelopersMenu extends React.Component {
   leaveDevelopers = e => {
     const { intl, dispatch } = this.props;
 
-    dispatch(changeSetting(['isDeveloper'], false));
+    dispatch(changeSettingImmediate(['isDeveloper'], false));
     dispatch(snackbar.success(intl.formatMessage(messages.leave)));
 
     this.context.router.history.push('/');
diff --git a/app/soapbox/globals.js b/app/soapbox/globals.js
index 3b49e1fe6..08e773695 100644
--- a/app/soapbox/globals.js
+++ b/app/soapbox/globals.js
@@ -2,7 +2,7 @@
  * globals: do things through the console.
  * This feature is for developers.
  */
-import { changeSetting } from 'soapbox/actions/settings';
+import { changeSettingImmediate } from 'soapbox/actions/settings';
 
 export const createGlobals = store => {
   const Soapbox = {
@@ -11,7 +11,7 @@ export const createGlobals = store => {
       if (![true, false].includes(bool)) {
         throw `Invalid option ${bool}. Must be true or false.`;
       }
-      store.dispatch(changeSetting(['isDeveloper'], bool));
+      store.dispatch(changeSettingImmediate(['isDeveloper'], bool));
       return bool;
     },
   };