Skip to content

Commit

Permalink
fix(docsearch): don't add search to recent searches if favorited
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 3, 2020
1 parent 858a498 commit f00672a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/DocSearch.tsx
Expand Up @@ -61,6 +61,18 @@ export function DocSearch({
})
).current;

function saveRecentSearch(item: StoredDocSearchHit) {
// We save the recent search only if it's not favorited.
if (
favoriteSearches
.getAll()
.findIndex(search => search.objectID === item.objectID) === -1
) {
console.log('SAVED SEARCH');
recentSearches.add(item);
}
}

const autocomplete = React.useMemo(
() =>
createAutocomplete<
Expand Down Expand Up @@ -139,7 +151,7 @@ export function DocSearch({
return [
{
onSelect({ suggestion }) {
recentSearches.add(suggestion);
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
Expand All @@ -151,7 +163,7 @@ export function DocSearch({
},
{
onSelect({ suggestion }) {
recentSearches.add(suggestion);
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
Expand All @@ -167,7 +179,7 @@ export function DocSearch({
return Object.values<DocSearchHit[]>(sources).map(items => {
return {
onSelect({ suggestion }) {
recentSearches.add(suggestion);
saveRecentSearch(suggestion);
onClose();
},
getSuggestionUrl({ suggestion }) {
Expand Down Expand Up @@ -280,7 +292,7 @@ export function DocSearch({
recentSearches={recentSearches}
favoriteSearches={favoriteSearches}
onItemClick={item => {
recentSearches.add(item);
saveRecentSearch(item);
onClose();
}}
inputRef={inputRef}
Expand Down

0 comments on commit f00672a

Please sign in to comment.