Skip to content

Commit

Permalink
fix(docsearch): don't request Algolia on start screen
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 6, 2020
1 parent bf86a1d commit e661435
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/DocSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ export function DocSearch({
setState(state as any);
},
getSources({ query, state, setContext, setStatus }) {
if (!query) {
return [
{
onSelect({ suggestion }) {
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
return suggestion.url;
},
getSuggestions() {
return recentSearches.getAll();
},
},
{
onSelect({ suggestion }) {
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
return suggestion.url;
},
getSuggestions() {
return favoriteSearches.getAll();
},
},
];
}

return getAlgoliaHits({
searchClient,
queries: [
Expand Down Expand Up @@ -174,35 +203,6 @@ export function DocSearch({
});
}

if (!query) {
return [
{
onSelect({ suggestion }) {
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
return suggestion.url;
},
getSuggestions() {
return recentSearches.getAll();
},
},
{
onSelect({ suggestion }) {
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
return suggestion.url;
},
getSuggestions() {
return favoriteSearches.getAll();
},
},
];
}

return Object.values<DocSearchHit[]>(sources).map(items => {
return {
onSelect({ suggestion }) {
Expand Down

0 comments on commit e661435

Please sign in to comment.