move settingsleftpane to hooks

pull/1540/head
Audric Ackermann 5 years ago
parent eb30c7823c
commit 51452c5406
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { DefaultTheme } from 'styled-components';
import { SmartSessionConversation } from '../state/smart/SessionConversation'; import { SmartSessionConversation } from '../state/smart/SessionConversation';
import { import {
SessionSettingCategory, SessionSettingCategory,
@ -9,34 +8,19 @@ import {
const FilteredSettingsView = SmartSettingsView as any; const FilteredSettingsView = SmartSettingsView as any;
interface Props { type Props = {
focusedSettingsSection?: SessionSettingCategory; focusedSettingsSection?: SessionSettingCategory;
} };
export class SessionMainPanel extends React.Component<Props> { export const SessionMainPanel = (props: Props) => {
public constructor(props: Props) { const isSettingsView = props.focusedSettingsSection !== undefined;
super(props);
}
public render() {
const isSettingsView = this.props.focusedSettingsSection !== undefined;
return isSettingsView
? this.renderSettings()
: this.renderSessionConversation();
}
private renderSettings() {
const category = this.props.focusedSettingsSection;
return <FilteredSettingsView category={category} />;
}
private renderSessionConversation() { if (isSettingsView) {
return ( return <FilteredSettingsView category={props.focusedSettingsSection} />;
<div className="session-conversation">
<SmartSessionConversation />
</div>
);
} }
} return (
<div className="session-conversation">
<SmartSessionConversation />
</div>
);
};

@ -12,205 +12,158 @@ import {
import { SessionIcon, SessionIconSize, SessionIconType } from './icon'; import { SessionIcon, SessionIconSize, SessionIconType } from './icon';
import { SessionSearchInput } from './SessionSearchInput'; import { SessionSearchInput } from './SessionSearchInput';
import { SessionSettingCategory } from './settings/SessionSettings'; import { SessionSettingCategory } from './settings/SessionSettings';
import { DefaultTheme } from 'styled-components'; import { DefaultTheme, useTheme } from 'styled-components';
import { LeftPaneSectionHeader } from './LeftPaneSectionHeader'; import { LeftPaneSectionHeader } from './LeftPaneSectionHeader';
import { deleteAccount } from '../../util/accountManager'; import { deleteAccount } from '../../util/accountManager';
import { useDispatch, useSelector } from 'react-redux';
import { showSettingsSection } from '../../state/ducks/section';
import { getFocusedSettingsSection } from '../../state/selectors/section';
interface Props { type Props = {
settingsCategory: SessionSettingCategory; settingsCategory: SessionSettingCategory;
showSettingsSection: (category: SessionSettingCategory) => void; showSettingsSection: (category: SessionSettingCategory) => void;
theme: DefaultTheme; theme: DefaultTheme;
} };
export interface State { const getCategories = () => {
searchQuery: string; return [
} {
id: SessionSettingCategory.Appearance,
export class LeftPaneSettingSection extends React.Component<Props, State> { title: window.i18n('appearanceSettingsTitle'),
public constructor(props: any) { hidden: false,
super(props); },
{
this.state = { id: SessionSettingCategory.Privacy,
searchQuery: '', title: window.i18n('privacySettingsTitle'),
}; hidden: false,
},
this.onDeleteAccount = this.onDeleteAccount.bind(this); {
} id: SessionSettingCategory.Blocked,
title: window.i18n('blockedSettingsTitle'),
public render(): JSX.Element { hidden: false,
return ( },
<div className="left-pane-setting-section"> {
{this.renderHeader()} id: SessionSettingCategory.Permissions,
{this.renderSettings()} title: window.i18n('permissionSettingsTitle'),
hidden: true,
},
{
id: SessionSettingCategory.Notifications,
title: window.i18n('notificationsSettingsTitle'),
hidden: false,
},
];
};
const LeftPaneSettingsCategoryRow = (props: { item: any }) => {
const { item } = props;
const dispatch = useDispatch();
const theme = useTheme();
const focusedSettingsSection = useSelector(getFocusedSettingsSection);
return (
<div
key={item.id}
className={classNames(
'left-pane-setting-category-list-item',
item.id === focusedSettingsSection ? 'active' : ''
)}
role="link"
onClick={() => {
dispatch(showSettingsSection(item.id));
}}
>
<div>
<strong>{item.title}</strong>
</div> </div>
);
}
public renderHeader(): JSX.Element | undefined { <div>
return ( {item.id === focusedSettingsSection && (
<LeftPaneSectionHeader <SessionIcon
label={window.i18n('settingsHeader')} iconSize={SessionIconSize.Medium}
theme={this.props.theme} iconType={SessionIconType.Chevron}
/> iconRotation={270}
); theme={theme}
} />
public renderRow(item: any): JSX.Element {
const { settingsCategory } = this.props;
return (
<div
key={item.id}
className={classNames(
'left-pane-setting-category-list-item',
item.id === settingsCategory ? 'active' : ''
)} )}
role="link"
onClick={() => {
this.props.showSettingsSection(item.id);
}}
>
<div>
<strong>{item.title}</strong>
</div>
<div>
{item.id === settingsCategory && (
<SessionIcon
iconSize={SessionIconSize.Medium}
iconType={SessionIconType.Chevron}
iconRotation={270}
theme={this.props.theme}
/>
)}
</div>
</div> </div>
); </div>
} );
};
public renderCategories(): JSX.Element {
const categories = this.getCategories().filter(item => !item.hidden); const LeftPaneSettingsCategories = () => {
const categories = getCategories();
return (
<div className="module-left-pane__list" key={0}> return (
<div className="left-pane-setting-category-list"> <div className="module-left-pane__list" key={0}>
{categories.map(item => this.renderRow(item))} <div className="left-pane-setting-category-list">
</div> {categories
.filter(m => !m.hidden)
.map(item => {
return <LeftPaneSettingsCategoryRow key={item.id} item={item} />;
})}
</div> </div>
); </div>
} );
};
public renderSearch() { const onDeleteAccount = () => {
return ( const title = window.i18n('clearAllData');
<div className="left-pane-setting-content">
<div className="left-pane-setting-input-group">
<SessionSearchInput
searchString={this.state.searchQuery}
onChange={() => null}
placeholder=""
theme={this.props.theme}
/>
<div className="left-pane-setting-input-button">
<SessionButton
buttonType={SessionButtonType.Square}
buttonColor={SessionButtonColor.Green}
theme={this.props.theme}
>
<SessionIcon
iconType={SessionIconType.Caret}
iconSize={SessionIconSize.Huge}
theme={this.props.theme}
/>
</SessionButton>
</div>
</div>
</div>
);
}
public renderSettings(): JSX.Element { const message = window.i18n('unpairDeviceWarning');
const showSearch = false;
return ( let messageSub = '';
<div className="left-pane-setting-content">
{showSearch && this.renderSearch()}
{this.renderCategories()}
{this.renderBottomButtons()}
</div>
);
}
public renderBottomButtons(): JSX.Element | undefined { const identityKey = window.textsecure.storage.get('identityKey');
const dangerButtonText = window.i18n('clearAllData'); if (identityKey && identityKey.ed25519KeyPair === undefined) {
const showRecoveryPhrase = window.i18n('showRecoveryPhrase'); messageSub =
"We've updated the way Session IDs are generated, so you will not be able to restore your current Session ID.";
return (
<div className="left-pane-setting-bottom-buttons">
<SessionButton
text={dangerButtonText}
buttonType={SessionButtonType.SquareOutline}
buttonColor={SessionButtonColor.Danger}
onClick={this.onDeleteAccount}
/>
<SessionButton
text={showRecoveryPhrase}
buttonType={SessionButtonType.SquareOutline}
buttonColor={SessionButtonColor.White}
onClick={() => window.Whisper.events.trigger('showSeedDialog')}
/>
</div>
);
} }
public onDeleteAccount() { window.confirmationDialog({
const title = window.i18n('clearAllData'); title,
message,
const message = window.i18n('unpairDeviceWarning'); messageSub,
resolve: deleteAccount,
let messageSub = ''; okTheme: 'danger',
});
const identityKey = window.textsecure.storage.get('identityKey'); };
if (identityKey && identityKey.ed25519KeyPair === undefined) {
messageSub = const LeftPaneBottomButtons = () => {
"We've updated the way Session IDs are generated, so you will not be able to restore your current Session ID."; const dangerButtonText = window.i18n('clearAllData');
} const showRecoveryPhrase = window.i18n('showRecoveryPhrase');
return (
<div className="left-pane-setting-bottom-buttons">
<SessionButton
text={dangerButtonText}
buttonType={SessionButtonType.SquareOutline}
buttonColor={SessionButtonColor.Danger}
onClick={onDeleteAccount}
/>
window.confirmationDialog({ <SessionButton
title, text={showRecoveryPhrase}
message, buttonType={SessionButtonType.SquareOutline}
messageSub, buttonColor={SessionButtonColor.White}
resolve: deleteAccount, onClick={() => window.Whisper.events.trigger('showSeedDialog')}
okTheme: 'danger', />
}); </div>
} );
};
public getCategories() { export const LeftPaneSettingSection = (props: Props) => {
return [ return (
{ <div className="left-pane-setting-section">
id: SessionSettingCategory.Appearance, <LeftPaneSectionHeader
title: window.i18n('appearanceSettingsTitle'), label={window.i18n('settingsHeader')}
hidden: false, theme={props.theme}
}, />
{ <div className="left-pane-setting-content">
id: SessionSettingCategory.Privacy, <LeftPaneSettingsCategories />
title: window.i18n('privacySettingsTitle'), <LeftPaneBottomButtons />
hidden: false, </div>
}, </div>
{ );
id: SessionSettingCategory.Blocked, };
title: window.i18n('blockedSettingsTitle'),
hidden: false,
},
{
id: SessionSettingCategory.Permissions,
title: window.i18n('permissionSettingsTitle'),
hidden: true,
},
{
id: SessionSettingCategory.Notifications,
title: window.i18n('notificationsSettingsTitle'),
hidden: false,
},
];
}
}

@ -14,7 +14,9 @@ type FocusSettingsSectionActionType = {
payload: SessionSettingCategory; payload: SessionSettingCategory;
}; };
function showLeftPaneSection(section: SectionType): FocusSectionActionType { export function showLeftPaneSection(
section: SectionType
): FocusSectionActionType {
return { return {
type: FOCUS_SECTION, type: FOCUS_SECTION,
payload: section, payload: section,
@ -25,7 +27,7 @@ type SectionActionTypes =
| FocusSectionActionType | FocusSectionActionType
| FocusSettingsSectionActionType; | FocusSettingsSectionActionType;
function showSettingsSection( export function showSettingsSection(
category: SessionSettingCategory category: SessionSettingCategory
): FocusSettingsSectionActionType { ): FocusSettingsSectionActionType {
return { return {

Loading…
Cancel
Save