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

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 c88cc79 commit 32a09c2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/docsearch-react/src/DocSearch.tsx
Original file line number Diff line number Diff line change
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 32a09c2

Please sign in to comment.