Skip to content

Commit

Permalink
Fix suggestion list when suggestions are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jan 4, 2024
1 parent fb035d3 commit 4218eef
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions isimip_data/search/assets/js/components/Suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ class Suggestions extends Component {

render() {
const { count, suggestions, onClick } = this.props
const suggestionsList = suggestions === null ? [] :suggestions.reduce((cur, agg) => {
if (cur.length > 0) agg.push(cur)
return agg
}, [])

return (count == 0) && (
<div className="card suggestions">
<div className="card-body">
<strong>No results found</strong>
{
suggestions && <>
suggestionsList.length > 0 && <>
<span className="ml-2">Maybe you misspelled your query. Did you mean:</span>
{
suggestions.map((suggestion, index) => (
suggestionsList.map((suggestion, index) => (
<button key={index} className="btn btn-link ml-2" onClick={() => onClick(suggestion)}>
{suggestion}
</button>
Expand Down

0 comments on commit 4218eef

Please sign in to comment.