MCPcopy Create free account
hub / github.com/algolia/docsearch / buildNoQuerySources

Function buildNoQuerySources

packages/docsearch-react/src/DocSearchModal.tsx:72–117  ·  view source on GitHub ↗
({
  recentSearches,
  favoriteSearches,
  saveRecentSearch,
  onClose,
  disableUserPersonalization,
}: BuildNoQuerySourcesOptions)

Source from the content-addressed store, hash-verified

70};
71
72const buildNoQuerySources = ({
73 recentSearches,
74 favoriteSearches,
75 saveRecentSearch,
76 onClose,
77 disableUserPersonalization,
78}: BuildNoQuerySourcesOptions): Array<AutocompleteSource<InternalDocSearchHit>> => {
79 if (disableUserPersonalization) {
80 return [];
81 }
82
83 const sources: Array<AutocompleteSource<InternalDocSearchHit>> = [
84 {
85 sourceId: 'recentSearches',
86 onSelect({ item, event }): void {
87 saveRecentSearch(item);
88 if (!isModifierEvent(event)) {
89 onClose();
90 }
91 },
92 getItemUrl({ item }): string {
93 return item.url;
94 },
95 getItems(): InternalDocSearchHit[] {
96 return recentSearches.getAll() as InternalDocSearchHit[];
97 },
98 },
99 {
100 sourceId: 'favoriteSearches',
101 onSelect({ item, event }): void {
102 saveRecentSearch(item);
103 if (!isModifierEvent(event)) {
104 onClose();
105 }
106 },
107 getItemUrl({ item }): string {
108 return item.url;
109 },
110 getItems(): InternalDocSearchHit[] {
111 return favoriteSearches.getAll() as InternalDocSearchHit[];
112 },
113 },
114 ];
115
116 return sources;
117};
118
119type BuildQuerySourcesState = Pick<AutocompleteState<InternalDocSearchHit>, 'context'>;
120

Callers 1

getSourcesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected