Settings: optionally show alert
This commit is contained in:
parent
017ee90dfd
commit
c1a0b7a6a8
3 changed files with 12 additions and 11 deletions
|
@ -177,7 +177,7 @@ const getSettings = createSelector([
|
|||
.mergeDeep(settings);
|
||||
});
|
||||
|
||||
const changeSettingImmediate = (path: string[], value: any) =>
|
||||
const changeSettingImmediate = (path: string[], value: any, showAlert = false) =>
|
||||
(dispatch: AppDispatch) => {
|
||||
dispatch({
|
||||
type: SETTING_CHANGE,
|
||||
|
@ -185,10 +185,10 @@ const changeSettingImmediate = (path: string[], value: any) =>
|
|||
value,
|
||||
});
|
||||
|
||||
dispatch(saveSettingsImmediate());
|
||||
dispatch(saveSettingsImmediate(showAlert));
|
||||
};
|
||||
|
||||
const changeSetting = (path: string[], value: any) =>
|
||||
const changeSetting = (path: string[], value: any, showAlert = false) =>
|
||||
(dispatch: AppDispatch) => {
|
||||
dispatch({
|
||||
type: SETTING_CHANGE,
|
||||
|
@ -196,10 +196,10 @@ const changeSetting = (path: string[], value: any) =>
|
|||
value,
|
||||
});
|
||||
|
||||
return dispatch(saveSettings());
|
||||
return dispatch(saveSettings(showAlert));
|
||||
};
|
||||
|
||||
const saveSettingsImmediate = () =>
|
||||
const saveSettingsImmediate = (showAlert = false) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return;
|
||||
|
||||
|
@ -215,14 +215,16 @@ const saveSettingsImmediate = () =>
|
|||
})).then(() => {
|
||||
dispatch({ type: SETTING_SAVE });
|
||||
|
||||
dispatch(snackbar.success(messages.saveSuccess));
|
||||
if (showAlert) {
|
||||
dispatch(snackbar.success(messages.saveSuccess));
|
||||
}
|
||||
}).catch(error => {
|
||||
dispatch(showAlertForError(error));
|
||||
});
|
||||
};
|
||||
|
||||
const saveSettings = () =>
|
||||
(dispatch: AppDispatch) => dispatch(saveSettingsImmediate());
|
||||
const saveSettings = (showAlert = false) =>
|
||||
(dispatch: AppDispatch) => dispatch(saveSettingsImmediate(showAlert));
|
||||
|
||||
export {
|
||||
SETTING_CHANGE,
|
||||
|
|
|
@ -13,7 +13,6 @@ interface ISettingToggle {
|
|||
settingPath: string[],
|
||||
/** Callback when the setting is toggled. */
|
||||
onChange: (settingPath: string[], checked: boolean) => void,
|
||||
|
||||
}
|
||||
|
||||
/** Stateful toggle to change user settings. */
|
||||
|
|
|
@ -96,11 +96,11 @@ const Preferences = () => {
|
|||
const settings = useAppSelector((state) => getSettings(state));
|
||||
|
||||
const onSelectChange = (event: React.ChangeEvent<HTMLSelectElement>, path: string[]) => {
|
||||
dispatch(changeSetting(path, event.target.value));
|
||||
dispatch(changeSetting(path, event.target.value, true));
|
||||
};
|
||||
|
||||
const onToggleChange = (key: string[], checked: boolean) => {
|
||||
dispatch(changeSetting(key, checked));
|
||||
dispatch(changeSetting(key, checked, true));
|
||||
};
|
||||
|
||||
const displayMediaOptions = React.useMemo(() => ({
|
||||
|
|
Loading…
Reference in a new issue