import React from 'react'; import {useQuery, useApolloClient} from 'react-apollo'; import { TrendingQueriesVariables, TrendingQueries } from 'generated_types/TrendingQueries'; import TRENDING_QUERIES_QUERY from 'shared/queries/trending_queries'; import { getSearchResults, getFlatResults, TSearchResultGroup } from 'shared/utils/search'; import {parseTrendingQueries} from 'shared/utils/trending_queries'; import {getMojoSiteConstants} from 'shared/utils/common'; import SearchBar, {Props as SearchBarProps} from './search_bar'; export type Theme = 'white' | 'light-grey'; interface Props extends SearchBarProps { showTrendingQueries?: boolean; } const SearchBarContainer: React.FC = ({ theme, placeholder, placeholderAlignment, defaultResults, onSubmit, searchSuggestionMessagingFlag, showTrendingQueries, doubleTapInput }: Props) => { const client = useApolloClient(); const trendingQueriesQuery = useQuery< TrendingQueries, TrendingQueriesVariables >(TRENDING_QUERIES_QUERY, { skip: !showTrendingQueries, variables: { limit: 3 + getFlatResults(defaultResults).length, abTests: getMojoSiteConstants().search_api_ab_tests, clientCountryCode: getMojoSiteConstants().client_country_code } }); if (trendingQueriesQuery.data) { defaultResults = [ ...parseTrendingQueries( trendingQueriesQuery.data, getFlatResults(defaultResults).map(result => result.name.toLowerCase()) ), ...defaultResults ]; } return ( => getSearchResults(query, client) } onSubmit={onSubmit} searchSuggestionMessagingFlag={searchSuggestionMessagingFlag} doubleTapInput={doubleTapInput} /> ); }; export default SearchBarContainer;