move the selectedSection state to the leftpanel object

pull/712/head
Audric Ackermann 6 years ago
parent c883d20bd7
commit 3893a26251

@ -12,7 +12,7 @@ import {
} from './SearchResults'; } from './SearchResults';
import { LocalizerType } from '../types/Util'; import { LocalizerType } from '../types/Util';
import { LeftPaneSections } from './LeftPaneSections'; import { LeftPaneSections, SectionType } from './LeftPaneSections';
export interface Props { export interface Props {
conversations?: Array<ConversationListItemPropsType>; conversations?: Array<ConversationListItemPropsType>;
@ -50,7 +50,12 @@ type RowRendererParamsType = {
export class LeftPane extends React.Component<Props> { export class LeftPane extends React.Component<Props> {
public state = { public state = {
currentTab: 'conversations', currentTab: 'conversations',
selectedSection: SectionType.Message,
}; };
public constructor(props: Props) {
super(props);
this.handleSectionSelected = this.handleSectionSelected.bind(this);
}
public getCurrentConversations(): public getCurrentConversations():
| Array<ConversationListItemPropsType> | Array<ConversationListItemPropsType>
@ -266,12 +271,20 @@ export class LeftPane extends React.Component<Props> {
); );
} }
public handleSectionSelected(section: SectionType) {
console.log('section switch to:', section);
this.setState({ selectedSection: section });
}
public render(): JSX.Element { public render(): JSX.Element {
const { renderMainHeader, showArchived } = this.props; const { renderMainHeader, showArchived } = this.props;
return ( return (
<div className="module-left-pane-session"> <div className="module-left-pane-session">
<LeftPaneSections /> <LeftPaneSections
selectedSection={this.state.selectedSection}
onSectionSelected={this.handleSectionSelected}
/>
<div className="module-left-pane"> <div className="module-left-pane">
<div className="module-left-pane__header"> <div className="module-left-pane__header">
{showArchived ? this.renderArchivedHeader() : renderMainHeader()} {showArchived ? this.renderArchivedHeader() : renderMainHeader()}

@ -6,7 +6,7 @@ import {
} from './session/icon'; } from './session/icon';
import { Avatar } from './Avatar'; import { Avatar } from './Avatar';
enum SectionType { export enum SectionType {
Profile, Profile,
Message, Message,
People, People,
@ -16,10 +16,14 @@ enum SectionType {
} }
interface State { interface State {
selectedSection: SectionType;
avatarPath: string; avatarPath: string;
} }
interface Props {
onSectionSelected: any;
selectedSection: SectionType;
}
const Section = ({ const Section = ({
isSelected, isSelected,
onSelect, onSelect,
@ -112,12 +116,11 @@ const Section = ({
} }
}; };
export class LeftPaneSections extends React.Component<{}, State> { export class LeftPaneSections extends React.Component<Props, State> {
constructor() { constructor(props: Props) {
super({}); super(props);
this.state = { this.state = {
avatarPath: '', avatarPath: '',
selectedSection: SectionType.Message,
}; };
} }
public componentDidMount() { public componentDidMount() {
@ -135,14 +138,14 @@ export class LeftPaneSections extends React.Component<{}, State> {
public render(): JSX.Element { public render(): JSX.Element {
const isProfileSelected = const isProfileSelected =
this.state.selectedSection === SectionType.Profile; this.props.selectedSection === SectionType.Profile;
const isMessageSelected = const isMessageSelected =
this.state.selectedSection === SectionType.Message; this.props.selectedSection === SectionType.Message;
const isPeopleSelected = this.state.selectedSection === SectionType.People; const isPeopleSelected = this.props.selectedSection === SectionType.People;
const isGlobeSelected = this.state.selectedSection === SectionType.Globe; const isGlobeSelected = this.props.selectedSection === SectionType.Globe;
const isSettingsSelected = const isSettingsSelected =
this.state.selectedSection === SectionType.Settings; this.props.selectedSection === SectionType.Settings;
const isMoonSelected = this.state.selectedSection === SectionType.Moon; const isMoonSelected = this.props.selectedSection === SectionType.Moon;
return ( return (
<div className="module-left-pane__sections-container"> <div className="module-left-pane__sections-container">
@ -183,6 +186,6 @@ export class LeftPaneSections extends React.Component<{}, State> {
} }
private readonly handleSectionSelect = (section: SectionType): void => { private readonly handleSectionSelect = (section: SectionType): void => {
this.setState({ selectedSection: section }); this.props.onSectionSelected(section);
}; };
} }

Loading…
Cancel
Save