Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Ensure suggestions is an array and close autocomplete on search #1040

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/SearchAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,14 @@ class SearchAutocomplete extends Component<Props & typeof defaultProps> {
};

render() {
const suggestions = this.getSuggestions();
const hasSuggestions = !!suggestions.length;

return (
<Container className={this.getSuggestions().length ? '' : 'hidden'}>
<Container className={hasSuggestions ? '' : 'hidden'}>
<List role="menu">
{!!this.getSuggestions().length &&
this.getSuggestions().map((item: SuggestionShape) => (
{hasSuggestions &&
suggestions.map((item: SuggestionShape) => (
<li key={item.href}>
<StyledLink>
<a href={item.href}>{item.ayah}</a>
Expand Down
2 changes: 2 additions & 0 deletions src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class SearchInput extends Component<Props> {
label: value,
});

this.handleHideAutocomplete();

return push(`/search?q=${value}`);
};

Expand Down
4 changes: 3 additions & 1 deletion src/redux/reducers/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default (state = INITIAL_STATE, action: $TsFixMe) => {
...prevState,
results: {
...state.results,
[action.meta.query]: camelcaseKeys(action.payload, { deep: true }),
[action.meta.query]: Array.isArray(action.payload)
? camelcaseKeys(action.payload, { deep: true })
: [],
},
}),
});
Expand Down