Skip to content

Commit

Permalink
feat(docsearch): save content record hit parent in recent searches
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 9, 2020
1 parent 6ad1848 commit 4d743bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/DocSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ export function DocSearch({
).current;

const saveRecentSearch = React.useCallback(
function saveRecentSearch(item: StoredDocSearchHit) {
function saveRecentSearch(item: InternalDocSearchHit) {
// We don't store `content` record, but their parent if available.
const search = item.type === 'content' ? item.__docsearch_parent : item;

// We save the recent search only if it's not favorited.
if (
search &&
favoriteSearches
.getAll()
.findIndex(search => search.objectID === item.objectID) === -1
.findIndex(x => x.objectID === search.objectID) === -1
) {
recentSearches.add(item);
recentSearches.add(search);
}
},
[favoriteSearches, recentSearches]
Expand Down
4 changes: 0 additions & 4 deletions src/stored-searches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export function createStoredSearches<TItem extends StoredDocSearchHit>({
...hit
} = (item as unknown) as DocSearchHit;

if (hit.type === 'content') {
return;
}

const isQueryAlreadySaved = items.findIndex(
x => x.objectID === hit.objectID
);
Expand Down

0 comments on commit 4d743bc

Please sign in to comment.