import React from 'react'; import { PropsData as ConversationListItemPropsType } from './ConversationListItem'; import { LocalizerType } from '../types/Util'; import classNames from 'classnames'; export type PropsData = { contacts: Array; regionCode: string; searchTerm: string; selectedContact: number; onContactSelected: any; }; type PropsHousekeeping = { i18n: LocalizerType; }; type Props = PropsData & PropsHousekeeping; export class UserSearchResults extends React.Component { public constructor(props: Props) { super(props); } public render() { const { contacts, i18n, searchTerm } = this.props; const haveContacts = contacts && contacts.length; const noResults = !haveContacts; return (
{noResults ? (
{i18n('noSearchResults', [searchTerm])}
) : null} {haveContacts ? this.renderContacts(contacts) : null}
); } private renderContacts(items: Array) { return (
{items.map((contact, index) => this.renderContact(contact, index))}
); } private renderContact(contact: ConversationListItemPropsType, index: Number) { const { profileName, phoneNumber } = contact; const { selectedContact } = this.props; const shortenedPubkey = window.shortenPubkey(phoneNumber); const rowContent = `${profileName} ${shortenedPubkey}`; return (
this.props.onContactSelected(contact.phoneNumber)} role="button" > {rowContent}
); } }