diff --git a/client/src/components/search/searchBar/NoHitsSuggestion.js b/client/src/components/search/searchBar/NoHitsSuggestion.js new file mode 100644 index 0000000000..89a034edf5 --- /dev/null +++ b/client/src/components/search/searchBar/NoHitsSuggestion.js @@ -0,0 +1,22 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +const NoHitsSuggestion = ({ title, handleMouseEnter, handleMouseLeave }) => { + return ( +
+ {title} +
+ ); +}; + +NoHitsSuggestion.propTypes = { + handleMouseEnter: PropTypes.func.isRequired, + handleMouseLeave: PropTypes.func.isRequired, + title: PropTypes.string +}; + +export default NoHitsSuggestion; diff --git a/client/src/components/search/searchBar/SearchHits.js b/client/src/components/search/searchBar/SearchHits.js index 12ee0b8215..cfe953ca17 100644 --- a/client/src/components/search/searchBar/SearchHits.js +++ b/client/src/components/search/searchBar/SearchHits.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { connectStateResults, connectHits } from 'react-instantsearch-dom'; import isEmpty from 'lodash/isEmpty'; import Suggestion from './SearchSuggestion'; +import NoHitsSuggestion from './NoHitsSuggestion'; const CustomHits = connectHits( ({ @@ -14,6 +15,7 @@ const CustomHits = connectHits( handleHits }) => { const noHits = isEmpty(hits); + const noHitsTitle = 'No tutorials found'; const footer = [ { objectID: `footer-${searchQuery}`, @@ -23,13 +25,11 @@ const CustomHits = connectHits( : `https://www.freecodecamp.org/news/search/?query=${encodeURIComponent( searchQuery )}`, - title: noHits - ? 'No tutorials found' - : `See all results for ${searchQuery}`, + title: noHits ? noHitsTitle : `See all results for ${searchQuery}`, _highlightResult: { query: { value: noHits - ? 'No tutorials found' + ? noHitsTitle : ` See all results for @@ -56,11 +56,19 @@ const CustomHits = connectHits( data-fccobjectid={hit.objectID} key={hit.objectID} > - + {noHits ? ( + + ) : ( + + )} ))} diff --git a/client/src/components/search/searchBar/SearchSuggestion.js b/client/src/components/search/searchBar/SearchSuggestion.js index f63a4f148a..ef7c672f1e 100644 --- a/client/src/components/search/searchBar/SearchSuggestion.js +++ b/client/src/components/search/searchBar/SearchSuggestion.js @@ -4,16 +4,7 @@ import { Highlight } from 'react-instantsearch-dom'; const Suggestion = ({ hit, handleMouseEnter, handleMouseLeave }) => { const dropdownFooter = hit.objectID.includes('footer-'); - const noHits = hit.title === 'No tutorials found'; - return noHits ? ( -
- {hit.title} -
- ) : ( + return (