Merge branch 'settings-instant' into 'develop'
Settings: save isDeveloper instantly, change developer challenge Closes #800 See merge request soapbox-pub/soapbox-fe!979
This commit is contained in:
commit
76dff42c7d
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
|||
<FormattedMessage
|
||||
id='developers.challenge.message'
|
||||
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'>
|
||||
{challenge}
|
||||
|
|
|
@ -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('/');
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue