import { localize } from 'i18n-calypso'; import PropTypes from 'prop-types'; import { Component } from 'react'; import { connect } from 'react-redux'; import QueryReaderFeedsSearch from 'calypso/components/data/query-reader-feeds-search'; import withDimensions from 'calypso/lib/with-dimensions'; import ReaderInfiniteStream from 'calypso/reader/components/reader-infinite-stream'; import { siteRowRenderer } from 'calypso/reader/components/reader-infinite-stream/row-renderers'; import { SEARCH_RESULTS_SITES } from 'calypso/reader/follow-sources'; import { MAX_POSTS_FOR_LOGGED_OUT_USERS } from 'calypso/reader/reader.const'; import { isUserLoggedIn } from 'calypso/state/current-user/selectors'; import { requestFeedSearch, SORT_BY_RELEVANCE, SORT_BY_LAST_UPDATED, } from 'calypso/state/reader/feed-searches/actions'; import { getReaderFeedsForQuery, getReaderFeedsCountForQuery, } from 'calypso/state/reader/feed-searches/selectors'; import { getFeed } from 'calypso/state/reader/feeds/selectors'; class SiteResults extends Component { static propTypes = { query: PropTypes.string, sort: PropTypes.oneOf( [ SORT_BY_LAST_UPDATED, SORT_BY_RELEVANCE ] ), requestFeedSearch: PropTypes.func, onReceiveSearchResults: PropTypes.func, searchResults: PropTypes.array, searchResultsCount: PropTypes.number, width: PropTypes.number.isRequired, }; fetchNextPage = ( offset ) => { if ( this.isLoginPromptVisible( offset ) ) { return; } this.props.requestFeedSearch( { query: this.props.query, offset, excludeFollowed: false, sort: this.props.sort, } ); }; hasNextPage = ( offset ) => { if ( this.isLoginPromptVisible( offset ) ) { return false; } return offset < this.props.searchResultsCount; }; isLoginPromptVisible( offset ) { // Show login prompt for all logged out users after few posts. return ! this.props.isLoggedIn && offset > MAX_POSTS_FOR_LOGGED_OUT_USERS; } render() { const { query, searchResults, width, sort } = this.props; const isEmpty = query?.length > 0 && searchResults?.length === 0; if ( isEmpty ) { return (