feat(phone/settings): Schema validation & Reset Settings

You can now reset your settings to default using the action in the Settings App

Setting schema validation has been added that will temporarily reset to default settings if
the JSON string contains unexpected values. A alert will pop up informing the user
that they should reset to default settings using the action in the settings app,
as a permanent solution.
This commit is contained in:
Taso committed 2021-03-20 12:57:22 -04:00
1 parent 97c308f550
commit 2a4457b323
6 files changed
+157 -29

No files matched your search

@@ -26,12 +26,14 @@ import {
VolumeUp,
FileCopy,
Book,
DeleteForever,
} from '@material-ui/icons';
import { ListSubheader } from '@material-ui/core';
import { useSettings } from '../hooks/useSettings';
import { useResetSettings, useSettings } from '../hooks/useSettings';
import { setClipboard } from '../../../os/phone/hooks/useClipboard';
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
import { IContextMenuOption } from '../../../ui/components/ContextMenu';
const SubHeaderComp = (props: { text: string }) => (
<ListSubheader color="primary" component="div" disableSticky>
@@ -48,6 +50,8 @@ export const SettingsApp = () => {
const { addAlert } = useSnackbar();
const resetSettings = useResetSettings();
const handleSettingChange = (key: string | number, value: unknown) => {
setSettings({ ...settings, [key]: value });
};
@@ -91,6 +95,23 @@ export const SettingsApp = () => {
MapSettingItem(settings.language, (val: SettingOption) => handleSettingChange('language', val)),
);
const handleResetOptions = () => {
resetSettings();
addAlert({
message: t('SETTINGS.MESSAGES.SETTINGS_RESET'),
type: 'success',
});
};
const resetSettingsOpts: IContextMenuOption[] = [
{
selected: false,
onClick: () => handleResetOptions(),
key: 'RESET_SETTINGS',
label: t('SETTINGS.OPTIONS.RESET_SETTINGS'),
},
];
const handleCopyPhoneNumber = () => {
setClipboard(simcard.number);
addAlert({
@@ -210,6 +231,15 @@ export const SettingsApp = () => {
icon={<VolumeUp />}
/>
</List>
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.ACTIONS')} />}>
<SettingItem
label={t('SETTINGS.OPTIONS.RESET_SETTINGS')}
value={`${t('SETTINGS.OPTIONS.RESET_SETTINGS_DESC')}`}
icon={<DeleteForever />}
onClick={openMenu}
options={resetSettingsOpts}
/>
</List>
</AppContent>
<ContextMenu />
</AppWrapper>