Merge branch 'settings-instant' into 'develop'

Settings: save isDeveloper instantly, change developer challenge

Closes #800

See merge request soapbox-pub/soapbox-fe!979
merge-requests/980/head
Alex Gleason 3 years ago
commit 76dff42c7d

@ -168,6 +168,18 @@ export const getSettings = createSelector([
.mergeDeep(settings); .mergeDeep(settings);
}); });
export function changeSettingImmediate(path, value) {
return dispatch => {
dispatch({
type: SETTING_CHANGE,
path,
value,
});
dispatch(saveSettingsImmediate());
};
}
export function changeSetting(path, value) { export function changeSetting(path, value) {
return dispatch => { return dispatch => {
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) => { const debouncedSave = debounce((dispatch, getState) => {
if (!isLoggedIn(getState)) return; dispatch(saveSettingsImmediate());
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));
});
}, 5000, { trailing: true }); }, 5000, { trailing: true });
export function saveSettings() { export function saveSettings() {

@ -3,7 +3,7 @@ import React from 'react';
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { changeSetting } from 'soapbox/actions/settings'; import { changeSettingImmediate } from 'soapbox/actions/settings';
import snackbar from 'soapbox/actions/snackbar'; import snackbar from 'soapbox/actions/snackbar';
import { SimpleForm, TextInput } from 'soapbox/features/forms'; import { SimpleForm, TextInput } from 'soapbox/features/forms';
@ -38,8 +38,8 @@ class DevelopersChallenge extends React.Component {
const { intl, dispatch } = this.props; const { intl, dispatch } = this.props;
const { answer } = this.state; const { answer } = this.state;
if (answer === 'buzzfizz') { if (answer === 'boxsoap') {
dispatch(changeSetting(['isDeveloper'], true)); dispatch(changeSettingImmediate(['isDeveloper'], true));
dispatch(snackbar.success(intl.formatMessage(messages.success))); dispatch(snackbar.success(intl.formatMessage(messages.success)));
} else { } else {
dispatch(snackbar.error(intl.formatMessage(messages.fail))); dispatch(snackbar.error(intl.formatMessage(messages.fail)));
@ -49,8 +49,8 @@ class DevelopersChallenge extends React.Component {
render() { render() {
const { intl } = this.props; const { intl } = this.props;
const challenge = `function fizzbuzz() { const challenge = `function soapbox() {
return 'fizz|buzz'.split('|').reverse().join(''); return 'soap|box'.split('|').reverse().join('');
}`; }`;
return ( return (
@ -60,7 +60,7 @@ class DevelopersChallenge extends React.Component {
<FormattedMessage <FormattedMessage
id='developers.challenge.message' id='developers.challenge.message'
defaultMessage='What is the result of calling {function}?' defaultMessage='What is the result of calling {function}?'
values={{ function: <span className='code'>fizzbuzz()</span> }} values={{ function: <span className='code'>soapbox()</span> }}
/> />
<pre className='code'> <pre className='code'>
{challenge} {challenge}

@ -4,7 +4,7 @@ import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Link } from 'react-router-dom'; 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 snackbar from 'soapbox/actions/snackbar';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
@ -31,7 +31,7 @@ class DevelopersMenu extends React.Component {
leaveDevelopers = e => { leaveDevelopers = e => {
const { intl, dispatch } = this.props; const { intl, dispatch } = this.props;
dispatch(changeSetting(['isDeveloper'], false)); dispatch(changeSettingImmediate(['isDeveloper'], false));
dispatch(snackbar.success(intl.formatMessage(messages.leave))); dispatch(snackbar.success(intl.formatMessage(messages.leave)));
this.context.router.history.push('/'); this.context.router.history.push('/');

@ -2,7 +2,7 @@
* globals: do things through the console. * globals: do things through the console.
* This feature is for developers. * This feature is for developers.
*/ */
import { changeSetting } from 'soapbox/actions/settings'; import { changeSettingImmediate } from 'soapbox/actions/settings';
export const createGlobals = store => { export const createGlobals = store => {
const Soapbox = { const Soapbox = {
@ -11,7 +11,7 @@ export const createGlobals = store => {
if (![true, false].includes(bool)) { if (![true, false].includes(bool)) {
throw `Invalid option ${bool}. Must be true or false.`; throw `Invalid option ${bool}. Must be true or false.`;
} }
store.dispatch(changeSetting(['isDeveloper'], bool)); store.dispatch(changeSettingImmediate(['isDeveloper'], bool));
return bool; return bool;
}, },
}; };

Loading…
Cancel
Save