import React from 'react'; import classNames from 'classnames'; import { Avatar } from '../Avatar'; import { SessionIcon, SessionIconSize, SessionIconType } from './icon'; import { Constants } from '../../session'; import { DefaultTheme, withTheme } from 'styled-components'; export interface ContactType { id: string; selected: boolean; authorProfileName: string; authorPhoneNumber: string; authorName: string; authorAvatarPath: string; checkmarked: boolean; existingMember: boolean; } interface Props { member: ContactType; index: number; // index in the list isSelected: boolean; onSelect?: any; onUnselect?: any; theme: DefaultTheme; } interface State { isSelected: boolean; } class SessionMemberListItemInner extends React.Component { public static defaultProps = { isSelected: false, }; constructor(props: any) { super(props); this.state = { isSelected: this.props.isSelected, }; this.handleSelectionAction = this.handleSelectionAction.bind(this); this.selectMember = this.selectMember.bind(this); this.unselectMember = this.unselectMember.bind(this); this.renderAvatar = this.renderAvatar.bind(this); } public render() { const { isSelected } = this.state; const name = this.props.member.authorProfileName; return (
{this.renderAvatar()} {name}
); } private renderAvatar() { const { authorAvatarPath, authorName, authorPhoneNumber, authorProfileName, } = this.props.member; const userName = authorName || authorProfileName || authorPhoneNumber; return ( ); } private handleSelectionAction() { if (this.state.isSelected) { this.unselectMember(); return; } this.selectMember(); } private selectMember() { this.setState({ isSelected: true, }); if (this.props.onSelect) { this.props.onSelect(this.props.member); } } private unselectMember() { this.setState({ isSelected: false, }); if (this.props.onUnselect) { this.props.onUnselect(this.props.member); } } } export const SessionMemberListItem = SessionMemberListItemInner;