diff --git a/client/src/components/search/searchBar/SearchBar.js b/client/src/components/search/searchBar/SearchBar.js index be3332df69..cf5586c084 100644 --- a/client/src/components/search/searchBar/SearchBar.js +++ b/client/src/components/search/searchBar/SearchBar.js @@ -112,8 +112,9 @@ export class SearchBar extends Component { // return navigate('/search'); // Temporary redirect to News search results page - // when non-empty search input submitted - return query + // when non-empty search input submitted and there + // are hits besides the footer + return query && hits.length > 1 ? window.location.assign( `https://www.freecodecamp.org/news/search/?query=${encodeURIComponent( query diff --git a/client/src/components/search/searchBar/SearchHits.js b/client/src/components/search/searchBar/SearchHits.js index 75635a4a38..12ee0b8215 100644 --- a/client/src/components/search/searchBar/SearchHits.js +++ b/client/src/components/search/searchBar/SearchHits.js @@ -13,22 +13,29 @@ const CustomHits = connectHits( selectedIndex, handleHits }) => { + const noHits = isEmpty(hits); const footer = [ { - objectID: `default-hit-${searchQuery}`, + objectID: `footer-${searchQuery}`, query: searchQuery, - url: `https://www.freecodecamp.org/news/search/?query=${encodeURIComponent( - searchQuery - )}`, - title: `See all results for ${searchQuery}`, + url: noHits + ? null + : `https://www.freecodecamp.org/news/search/?query=${encodeURIComponent( + searchQuery + )}`, + title: noHits + ? 'No tutorials found' + : `See all results for ${searchQuery}`, _highlightResult: { query: { - value: ` - See all results for - - ${searchQuery} - - ` + value: noHits + ? 'No tutorials found' + : ` + + See all results for + ${searchQuery} + + ` } } } diff --git a/client/src/components/search/searchBar/SearchSuggestion.js b/client/src/components/search/searchBar/SearchSuggestion.js index 1a936b04b0..f63a4f148a 100644 --- a/client/src/components/search/searchBar/SearchSuggestion.js +++ b/client/src/components/search/searchBar/SearchSuggestion.js @@ -1,11 +1,19 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Highlight } from 'react-instantsearch-dom'; -import { isEmpty } from 'lodash'; const Suggestion = ({ hit, handleMouseEnter, handleMouseLeave }) => { - const dropdownFooter = hit.objectID.includes('default-hit-'); - return isEmpty(hit) || isEmpty(hit.objectID) ? null : ( + const dropdownFooter = hit.objectID.includes('footer-'); + const noHits = hit.title === 'No tutorials found'; + return noHits ? ( +
+ {hit.title} +
+ ) : (