Skip to content

Commit

Permalink
Don't show any search results if the searchTerm length is less than t…
Browse files Browse the repository at this point in the history
…he minSearchLength.
  • Loading branch information
dan-searle committed Feb 1, 2019
1 parent 69ed7ad commit b5f80c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
9 changes: 3 additions & 6 deletions components/x-topic-search/src/TopicSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,20 @@ class TopicSearch extends Component {

if (searchTerm.length >= this.minSearchLength) {
this.getSuggestions(searchTerm, this.maxSuggestions, this.apiUrl, this.props.followedTopicIds)
.then(({ resultsForTerm, followedSuggestions, unfollowedSuggestions }) => {
.then(({ followedSuggestions, unfollowedSuggestions }) => {
this.setState({
resultsForTerm,
followedSuggestions,
unfollowedSuggestions,
showResult: true
});
})
.catch(() => {
this.setState({
resultsForTerm: null,
showResult: false
});
});
} else {
this.setState({
resultsForTerm: null,
showResult: false
});
}
Expand All @@ -86,7 +83,7 @@ class TopicSearch extends Component {

render() {
const { csrfToken, followedTopicIds } = this.props;
const { followedSuggestions, resultsForTerm, searchTerm, showResult, unfollowedSuggestions } = this.state;
const { followedSuggestions, searchTerm, showResult, unfollowedSuggestions } = this.state;

return (
<div className={ classNames(styles['container']) } ref={el => this.rootEl = el}>
Expand All @@ -110,7 +107,7 @@ class TopicSearch extends Component {
/>
</div>

{ showResult && resultsForTerm === searchTerm &&
{ showResult && searchTerm.length >= this.minSearchLength &&
<ResultContainer
followedSuggestions={ followedSuggestions }
unfollowedSuggestions={ unfollowedSuggestions }
Expand Down
1 change: 0 additions & 1 deletion components/x-topic-search/src/lib/get-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default (searchTerm, maxSuggestions, apiUrl, followedTopicIds) => {
return response.json();
})
.then(suggestions => ({
resultsForTerm: searchTerm,
followedSuggestions: suggestions.filter(suggestion => followedTopicIds.includes(suggestion.id)),
unfollowedSuggestions: suggestions.filter(suggestion => !followedTopicIds.includes(suggestion.id))
}));
Expand Down

0 comments on commit b5f80c5

Please sign in to comment.