diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 4b5be9367..81d7117fb 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -12,7 +12,7 @@ import { } from './SearchResults'; import { LocalizerType } from '../types/Util'; -import { LeftPaneSections } from './LeftPaneSections'; +import { LeftPaneSections, SectionType } from './LeftPaneSections'; export interface Props { conversations?: Array; @@ -50,7 +50,12 @@ type RowRendererParamsType = { export class LeftPane extends React.Component { public state = { currentTab: 'conversations', + selectedSection: SectionType.Message, }; + public constructor(props: Props) { + super(props); + this.handleSectionSelected = this.handleSectionSelected.bind(this); + } public getCurrentConversations(): | Array @@ -266,12 +271,20 @@ export class LeftPane extends React.Component { ); } + public handleSectionSelected(section: SectionType) { + console.log('section switch to:', section); + this.setState({ selectedSection: section }); + } + public render(): JSX.Element { const { renderMainHeader, showArchived } = this.props; return (
- +
{showArchived ? this.renderArchivedHeader() : renderMainHeader()} diff --git a/ts/components/LeftPaneSections.tsx b/ts/components/LeftPaneSections.tsx index ffa8da0c2..a69d1e6ed 100644 --- a/ts/components/LeftPaneSections.tsx +++ b/ts/components/LeftPaneSections.tsx @@ -6,7 +6,7 @@ import { } from './session/icon'; import { Avatar } from './Avatar'; -enum SectionType { +export enum SectionType { Profile, Message, People, @@ -16,10 +16,14 @@ enum SectionType { } interface State { - selectedSection: SectionType; avatarPath: string; } +interface Props { + onSectionSelected: any; + selectedSection: SectionType; +} + const Section = ({ isSelected, onSelect, @@ -112,12 +116,11 @@ const Section = ({ } }; -export class LeftPaneSections extends React.Component<{}, State> { - constructor() { - super({}); +export class LeftPaneSections extends React.Component { + constructor(props: Props) { + super(props); this.state = { avatarPath: '', - selectedSection: SectionType.Message, }; } public componentDidMount() { @@ -135,14 +138,14 @@ export class LeftPaneSections extends React.Component<{}, State> { public render(): JSX.Element { const isProfileSelected = - this.state.selectedSection === SectionType.Profile; + this.props.selectedSection === SectionType.Profile; const isMessageSelected = - this.state.selectedSection === SectionType.Message; - const isPeopleSelected = this.state.selectedSection === SectionType.People; - const isGlobeSelected = this.state.selectedSection === SectionType.Globe; + this.props.selectedSection === SectionType.Message; + const isPeopleSelected = this.props.selectedSection === SectionType.People; + const isGlobeSelected = this.props.selectedSection === SectionType.Globe; const isSettingsSelected = - this.state.selectedSection === SectionType.Settings; - const isMoonSelected = this.state.selectedSection === SectionType.Moon; + this.props.selectedSection === SectionType.Settings; + const isMoonSelected = this.props.selectedSection === SectionType.Moon; return (
@@ -183,6 +186,6 @@ export class LeftPaneSections extends React.Component<{}, State> { } private readonly handleSectionSelect = (section: SectionType): void => { - this.setState({ selectedSection: section }); + this.props.onSectionSelected(section); }; }