session-desktop/ts/components/session/LeftPaneSettingSection.tsx

233 lines
5.8 KiB
TypeScript
Raw Normal View History

2020-01-07 07:47:48 +01:00
import React from 'react';
import classNames from 'classnames';
import { LeftPane } from '../LeftPane';
import {
SessionButton,
SessionButtonColor,
SessionButtonType,
} from './SessionButton';
2020-01-08 07:21:39 +01:00
import { SessionIcon, SessionIconSize, SessionIconType } from './icon';
import { SessionSearchInput } from './SessionSearchInput';
2020-01-14 03:28:31 +01:00
import { SessionSettingCategory } from './settings/SessionSettings';
2020-01-07 07:47:48 +01:00
2020-04-30 09:34:55 +02:00
interface Props {
isSecondaryDevice: boolean;
2020-11-13 04:29:59 +01:00
settingsCategory: SessionSettingCategory;
showSessionSettingsCategory: (category: SessionSettingCategory) => void;
2020-04-30 09:34:55 +02:00
}
2020-01-07 07:47:48 +01:00
export interface State {
2020-01-08 07:21:39 +01:00
searchQuery: string;
2020-01-07 07:47:48 +01:00
}
2020-04-30 09:34:55 +02:00
export class LeftPaneSettingSection extends React.Component<Props, State> {
2020-01-15 03:49:07 +01:00
public constructor(props: any) {
2020-01-07 07:47:48 +01:00
super(props);
this.state = {
2020-01-08 07:21:39 +01:00
searchQuery: '',
2020-01-07 07:47:48 +01:00
};
this.setCategory = this.setCategory.bind(this);
2020-04-30 09:34:55 +02:00
this.onDeleteAccount = this.onDeleteAccount.bind(this);
2020-01-07 07:47:48 +01:00
}
public render(): JSX.Element {
2020-01-07 07:47:48 +01:00
return (
<div className="left-pane-setting-section">
2020-01-08 07:21:39 +01:00
{this.renderHeader()}
{this.renderSettings()}
2020-01-07 07:47:48 +01:00
</div>
);
}
public renderHeader(): JSX.Element | undefined {
const labels = [window.i18n('settingsHeader')];
return LeftPane.RENDER_HEADER(
labels,
null,
undefined,
undefined,
2020-05-07 05:46:36 +02:00
undefined,
2020-01-08 07:21:39 +01:00
undefined
2020-01-07 07:47:48 +01:00
);
}
public renderRow(item: any): JSX.Element {
const { settingsCategory } = this.props;
2020-01-07 07:47:48 +01:00
return (
<div
key={item.id}
className={classNames(
'left-pane-setting-category-list-item',
2020-11-13 04:29:59 +01:00
item.id === settingsCategory ? 'active' : ''
)}
role="link"
onClick={() => {
this.setCategory(item.id);
}}
>
<div>
<strong>{item.title}</strong>
</div>
<div>
2020-11-13 04:29:59 +01:00
{item.id === settingsCategory && (
<SessionIcon
iconSize={SessionIconSize.Medium}
iconType={SessionIconType.Chevron}
iconRotation={270}
/>
)}
</div>
</div>
2020-01-07 07:47:48 +01:00
);
}
2020-01-08 07:21:39 +01:00
public renderCategories(): JSX.Element {
const categories = this.getCategories().filter(item => !item.hidden);
2020-01-07 07:47:48 +01:00
return (
<div className="module-left-pane__list" key={0}>
2020-01-08 07:21:39 +01:00
<div className="left-pane-setting-category-list">
2020-01-23 01:53:02 +01:00
{categories.map(item => this.renderRow(item))}
2020-01-08 07:21:39 +01:00
</div>
2020-01-07 07:47:48 +01:00
</div>
2020-01-08 07:21:39 +01:00
);
2020-01-07 07:47:48 +01:00
}
2020-01-17 00:33:06 +01:00
public renderSearch() {
2020-01-07 07:47:48 +01:00
return (
<div className="left-pane-setting-content">
2020-01-08 07:21:39 +01:00
<div className="left-pane-setting-input-group">
<SessionSearchInput
searchString={this.state.searchQuery}
onChange={() => null}
placeholder=""
2020-01-08 07:21:39 +01:00
/>
<div className="left-pane-setting-input-button">
<SessionButton
buttonType={SessionButtonType.Square}
buttonColor={SessionButtonColor.Green}
2020-01-08 09:16:01 +01:00
>
<SessionIcon
2020-01-08 09:16:01 +01:00
iconType={SessionIconType.Caret}
2020-01-20 05:25:55 +01:00
iconSize={SessionIconSize.Huge}
2020-01-08 09:16:01 +01:00
/>
</SessionButton>
2020-01-08 07:21:39 +01:00
</div>
2020-01-21 00:56:30 +01:00
</div>
</div>
2020-01-17 00:33:06 +01:00
);
}
public renderSettings(): JSX.Element {
const showSearch = false;
return (
<div className="left-pane-setting-content">
{showSearch && this.renderSearch()}
2020-01-07 07:47:48 +01:00
{this.renderCategories()}
{this.renderBottomButtons()}
</div>
);
}
2020-04-30 09:34:55 +02:00
public renderBottomButtons(): JSX.Element | undefined {
const { isSecondaryDevice } = this.props;
const dangerButtonText = isSecondaryDevice
? window.i18n('unpairDevice')
2020-08-17 03:21:57 +02:00
: window.i18n('clearAllData');
const showRecoveryPhrase = window.i18n('showRecoveryPhrase');
2020-01-07 07:47:48 +01:00
return (
<div className="left-pane-setting-bottom-buttons">
<SessionButton
2020-04-30 09:34:55 +02:00
text={dangerButtonText}
2020-01-07 07:47:48 +01:00
buttonType={SessionButtonType.SquareOutline}
buttonColor={SessionButtonColor.Danger}
2020-01-08 07:21:39 +01:00
onClick={this.onDeleteAccount}
2020-01-07 07:47:48 +01:00
/>
2020-04-30 09:34:55 +02:00
{!isSecondaryDevice && (
<SessionButton
2020-08-17 03:21:57 +02:00
text={showRecoveryPhrase}
2020-04-30 09:34:55 +02:00
buttonType={SessionButtonType.SquareOutline}
buttonColor={SessionButtonColor.White}
onClick={window.showSeedDialog}
/>
)}
2020-01-07 07:47:48 +01:00
</div>
);
}
2020-01-08 07:21:39 +01:00
public onDeleteAccount() {
2020-04-30 09:34:55 +02:00
const { isSecondaryDevice } = this.props;
const title = window.i18n(
isSecondaryDevice ? 'unpairDevice' : 'clearAllData'
2020-04-30 09:34:55 +02:00
);
const message = window.i18n(
isSecondaryDevice ? 'unpairDeviceWarning' : 'deleteAccountWarning'
);
const messageSub = isSecondaryDevice
? window.i18n('unpairDeviceWarningSub')
: '';
2020-04-30 09:34:55 +02:00
window.confirmationDialog({
title,
message,
messageSub,
2020-01-08 07:21:39 +01:00
resolve: window.deleteAccount,
okTheme: 'danger',
2020-04-30 09:34:55 +02:00
});
2020-01-08 07:21:39 +01:00
}
public getCategories() {
2020-04-30 09:34:55 +02:00
const { isSecondaryDevice } = this.props;
2020-01-07 07:47:48 +01:00
return [
{
2020-02-04 01:55:01 +01:00
id: SessionSettingCategory.Appearance,
title: window.i18n('appearanceSettingsTitle'),
hidden: false,
},
2020-01-07 07:47:48 +01:00
{
id: SessionSettingCategory.Privacy,
2020-01-08 07:21:39 +01:00
title: window.i18n('privacySettingsTitle'),
hidden: false,
2020-01-07 07:47:48 +01:00
},
2020-07-30 16:49:11 +02:00
{
id: SessionSettingCategory.Blocked,
2020-08-06 09:35:01 +02:00
title: window.i18n('blockedSettingsTitle'),
hidden: false,
2020-07-30 16:49:11 +02:00
},
2020-01-15 02:26:14 +01:00
{
id: SessionSettingCategory.Permissions,
title: window.i18n('permissionSettingsTitle'),
2020-01-16 02:08:31 +01:00
hidden: true,
2020-01-15 02:26:14 +01:00
},
2020-01-07 07:47:48 +01:00
{
id: SessionSettingCategory.Notifications,
title: window.i18n('notificationsSettingsTitle'),
hidden: false,
2020-01-07 07:47:48 +01:00
},
{
id: SessionSettingCategory.Devices,
title: window.i18n('devicesSettingsTitle'),
hidden: !window.lokiFeatureFlags.useMultiDevice || isSecondaryDevice,
},
2020-01-07 07:47:48 +01:00
];
}
public setCategory(category: SessionSettingCategory) {
2020-11-13 04:29:59 +01:00
this.props.showSessionSettingsCategory(category);
2020-01-07 07:47:48 +01:00
}
}