Skip to content

Commit 4d743bc

Browse files
feat(docsearch): save content record hit parent in recent searches
1 parent 6ad1848 commit 4d743bc

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/DocSearch.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ export function DocSearch({
8383
).current;
8484

8585
const saveRecentSearch = React.useCallback(
86-
function saveRecentSearch(item: StoredDocSearchHit) {
86+
function saveRecentSearch(item: InternalDocSearchHit) {
87+
// We don't store `content` record, but their parent if available.
88+
const search = item.type === 'content' ? item.__docsearch_parent : item;
89+
8790
// We save the recent search only if it's not favorited.
8891
if (
92+
search &&
8993
favoriteSearches
9094
.getAll()
91-
.findIndex(search => search.objectID === item.objectID) === -1
95+
.findIndex(x => x.objectID === search.objectID) === -1
9296
) {
93-
recentSearches.add(item);
97+
recentSearches.add(search);
9498
}
9599
},
96100
[favoriteSearches, recentSearches]

src/stored-searches.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ export function createStoredSearches<TItem extends StoredDocSearchHit>({
6161
...hit
6262
} = (item as unknown) as DocSearchHit;
6363

64-
if (hit.type === 'content') {
65-
return;
66-
}
67-
6864
const isQueryAlreadySaved = items.findIndex(
6965
x => x.objectID === hit.objectID
7066
);

0 commit comments

Comments
 (0)