feat: update design of the Notification Settings screen
the preview button is not linked yetpull/2425/head
parent
9eae1289c7
commit
13bf0e073d
@ -1,42 +1,99 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
// tslint:disable-next-line: no-submodule-imports
|
||||||
|
import useUpdate from 'react-use/lib/useUpdate';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { SettingsKey } from '../../data/settings-key';
|
||||||
|
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
|
||||||
import { SessionRadioGroup } from '../basic/SessionRadioGroup';
|
import { SessionRadioGroup } from '../basic/SessionRadioGroup';
|
||||||
import { SessionSettingsItemWrapper } from './SessionSettingListItem';
|
import { SpacerLG } from '../basic/Text';
|
||||||
|
import { SessionSettingsItemWrapper, SessionToggleWithDescription } from './SessionSettingListItem';
|
||||||
|
// tslint:disable: use-simple-attributes
|
||||||
|
|
||||||
|
enum NOTIFICATION {
|
||||||
|
MESSAGE = 'message',
|
||||||
|
NAME = 'name',
|
||||||
|
COUNT = 'count',
|
||||||
|
OFF = 'off',
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledButtonContainer = styled.div`
|
||||||
|
display: flex;
|
||||||
|
width: min-content;
|
||||||
|
flex-direction: column;
|
||||||
|
padding-inline-start: var(--margins-lg);
|
||||||
|
`;
|
||||||
|
|
||||||
export const SessionNotificationGroupSettings = (props: { hasPassword: boolean | null }) => {
|
export const SessionNotificationGroupSettings = (props: { hasPassword: boolean | null }) => {
|
||||||
|
const forceUpdate = useUpdate();
|
||||||
|
|
||||||
if (props.hasPassword === null) {
|
if (props.hasPassword === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const initialItem =
|
||||||
|
window.getSettingValue(SettingsKey.settingsNotification) || NOTIFICATION.MESSAGE;
|
||||||
|
|
||||||
|
const notificationsAreEnabled = initialItem && initialItem !== NOTIFICATION.OFF;
|
||||||
|
|
||||||
const initialItem = window.getSettingValue('notification-setting') || 'message';
|
const onClickPreview = () => {
|
||||||
|
if (!notificationsAreEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
label: window.i18n('nameAndMessage'),
|
label: window.i18n('nameAndMessage'),
|
||||||
value: 'message',
|
value: NOTIFICATION.MESSAGE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: window.i18n('nameOnly'),
|
label: window.i18n('nameOnly'),
|
||||||
value: 'name',
|
value: NOTIFICATION.NAME,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: window.i18n('noNameOrMessage'),
|
label: window.i18n('noNameOrMessage'),
|
||||||
value: 'count',
|
value: NOTIFICATION.COUNT,
|
||||||
},
|
|
||||||
{
|
|
||||||
label: window.i18n('disableNotifications'),
|
|
||||||
value: 'off',
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SessionSettingsItemWrapper title={window.i18n('notificationSettingsDialog')} inline={false}>
|
<>
|
||||||
<SessionRadioGroup
|
<SessionToggleWithDescription
|
||||||
initialItem={initialItem}
|
onClickToggle={async () => {
|
||||||
group={'notification-setting'}
|
await window.setSettingValue(
|
||||||
items={items}
|
SettingsKey.settingsNotification,
|
||||||
onClick={(selectedRadioValue: string) => {
|
notificationsAreEnabled ? NOTIFICATION.OFF : NOTIFICATION.MESSAGE
|
||||||
window.setSettingValue('notification-setting', selectedRadioValue);
|
);
|
||||||
|
forceUpdate();
|
||||||
}}
|
}}
|
||||||
|
title={window.i18n('notificationsSettingsTitle')}
|
||||||
|
active={notificationsAreEnabled}
|
||||||
/>
|
/>
|
||||||
</SessionSettingsItemWrapper>
|
{notificationsAreEnabled ? (
|
||||||
|
<SessionSettingsItemWrapper
|
||||||
|
title={window.i18n('notificationsSettingsContent')}
|
||||||
|
description={window.i18n('notificationSettingsDialog')}
|
||||||
|
inline={false}
|
||||||
|
>
|
||||||
|
<SessionRadioGroup
|
||||||
|
initialItem={initialItem}
|
||||||
|
group={SettingsKey.settingsNotification}
|
||||||
|
items={items}
|
||||||
|
onClick={async (selectedRadioValue: string) => {
|
||||||
|
await window.setSettingValue(SettingsKey.settingsNotification, selectedRadioValue);
|
||||||
|
forceUpdate();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<StyledButtonContainer>
|
||||||
|
<SpacerLG />
|
||||||
|
<SessionButton
|
||||||
|
text={window.i18n('notificationPreview')}
|
||||||
|
buttonColor={SessionButtonColor.Green}
|
||||||
|
onClick={onClickPreview}
|
||||||
|
buttonType={SessionButtonType.BrandOutline}
|
||||||
|
/>
|
||||||
|
</StyledButtonContainer>
|
||||||
|
</SessionSettingsItemWrapper>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue