import React from 'react'; import styled, { CSSProperties } from 'styled-components'; import { useSelector } from 'react-redux'; import { AutoSizer, List } from 'react-virtualized'; import { isString } from 'lodash'; import { ConversationListItem } from '../leftpane/conversation-list-item/ConversationListItem'; import { MessageSearchResult } from './MessageSearchResults'; import { SearchResultsMergedListItem, getHasSearchResults, getSearchResultsList, getSearchTerm, } from '../../state/selectors/search'; const StyledSeparatorSection = styled.div` height: 36px; line-height: 36px; margin-inline-start: 16px; color: var(--text-secondary-color); font-size: var(--font-size-sm); font-weight: 400; letter-spacing: 0; `; const SearchResultsContainer = styled.div` overflow-y: auto; max-height: 100%; color: var(--text-secondary-color); flex-grow: 1; width: -webkit-fill-available; `; const NoResults = styled.div` margin-top: 27px; width: 100%; text-align: center; `; const SectionHeader = ({ title, style }: { title: string; style: CSSProperties }) => { return {title}; }; function isContact(item: SearchResultsMergedListItem): item is { contactConvoId: string } { return (item as any).contactConvoId !== undefined; } const VirtualizedList = () => { const searchResultList = useSelector(getSearchResultsList); return ( {({ height, width }) => ( { return isString(searchResultList[rowPos.index]) ? 36 : 64; }} rowRenderer={({ index, key, style }) => { const row = searchResultList[index]; if (!row) { return null; } if (isString(row)) { return ; } if (isContact(row)) { return ( ); } return ; }} width={width} autoHeight={false} /> )} ); }; export const SearchResults = () => { const searchTerm = useSelector(getSearchTerm); const hasSearchResults = useSelector(getHasSearchResults); return ( {!hasSearchResults ? ( {window.i18n('noSearchResults', [searchTerm])} ) : ( )} ); };