feat(docsearch): save content record hit parent in recent searches
This commit is contained in:
parent
6ad18485fd
commit
4d743bc48c
2 changed files with 7 additions and 7 deletions
|
|
@ -83,14 +83,18 @@ export function DocSearch({
|
||||||
).current;
|
).current;
|
||||||
|
|
||||||
const saveRecentSearch = React.useCallback(
|
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.
|
// We save the recent search only if it's not favorited.
|
||||||
if (
|
if (
|
||||||
|
search &&
|
||||||
favoriteSearches
|
favoriteSearches
|
||||||
.getAll()
|
.getAll()
|
||||||
.findIndex(search => search.objectID === item.objectID) === -1
|
.findIndex(x => x.objectID === search.objectID) === -1
|
||||||
) {
|
) {
|
||||||
recentSearches.add(item);
|
recentSearches.add(search);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[favoriteSearches, recentSearches]
|
[favoriteSearches, recentSearches]
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,6 @@ export function createStoredSearches<TItem extends StoredDocSearchHit>({
|
||||||
...hit
|
...hit
|
||||||
} = (item as unknown) as DocSearchHit;
|
} = (item as unknown) as DocSearchHit;
|
||||||
|
|
||||||
if (hit.type === 'content') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isQueryAlreadySaved = items.findIndex(
|
const isQueryAlreadySaved = items.findIndex(
|
||||||
x => x.objectID === hit.objectID
|
x => x.objectID === hit.objectID
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue