import React from 'react'; import { ConversationListItem, PropsData as ConversationListItemPropsType, } from './ConversationListItem'; import { MessageSearchResult, PropsData as MessageSearchResultPropsType, } from './MessageSearchResult'; import { StartNewConversation } from './StartNewConversation'; import { LocalizerType } from '../types/Util'; export type PropsData = { contacts: Array; conversations: Array; hideMessagesHeader: boolean; messages: Array; regionCode: string; searchTerm: string; showStartNewConversation: boolean; }; type PropsHousekeeping = { i18n: LocalizerType; openConversation: (id: string, messageId?: string) => void; startNewConversation: ( query: string, options: { regionCode: string } ) => void; }; type Props = PropsData & PropsHousekeeping; export class SearchResults extends React.Component { public handleStartNewConversation = () => { const { regionCode, searchTerm, startNewConversation } = this.props; startNewConversation(searchTerm, { regionCode }); }; public render() { const { conversations, contacts, hideMessagesHeader, i18n, messages, openConversation, searchTerm, showStartNewConversation, } = this.props; const haveConversations = conversations && conversations.length; const haveContacts = contacts && contacts.length; const haveMessages = messages && messages.length; const noResults = !showStartNewConversation && !haveConversations && !haveContacts && !haveMessages; return (
{noResults ? (
{i18n('noSearchResults', [searchTerm])}
) : null} {showStartNewConversation ? ( ) : null} {haveConversations ? (
{i18n('conversationsHeader')}
{conversations.map(conversation => ( ))}
) : null} {haveContacts ? (
{i18n('contactsHeader')}
{contacts.map(contact => ( ))}
) : null} {haveMessages ? (
{hideMessagesHeader ? null : (
{i18n('messagesHeader')}
)} {messages.map(message => ( ))}
) : null}
); } }