fix(types): use a minimal type for transformSearchClient (#2348)
This commit is contained in:
parent
57eace5541
commit
08d9a37807
3 changed files with 14 additions and 8 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import type { AutocompleteState, AutocompleteOptions } from '@algolia/autocomplete-core';
|
||||
import type { SearchClient } from 'algoliasearch';
|
||||
import type { SearchQuery, LiteClient } from 'algoliasearch/lite';
|
||||
import type { LiteClient, SearchForHits } from 'algoliasearch/lite';
|
||||
import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
|
|
@ -16,17 +15,24 @@ export type DocSearchTranslations = Partial<{
|
|||
modal: ModalTranslations;
|
||||
}>;
|
||||
|
||||
// The interface that describes the minimal implementation required for the algoliasearch client, when using the [`transformSearchClient`](https://docsearch.algolia.com/docs/api/#transformsearchclient) option.
|
||||
export type DocSearchTransformClient = {
|
||||
search: LiteClient['search'];
|
||||
addAlgoliaAgent: LiteClient['addAlgoliaAgent'];
|
||||
transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;
|
||||
};
|
||||
|
||||
export interface DocSearchProps {
|
||||
appId: string;
|
||||
apiKey: string;
|
||||
indexName: string;
|
||||
placeholder?: string;
|
||||
searchParameters?: SearchQuery;
|
||||
searchParameters?: SearchForHits;
|
||||
maxResultsPerGroup?: number;
|
||||
transformItems?: (items: DocSearchHit[]) => DocSearchHit[];
|
||||
hitComponent?: (props: { hit: InternalDocSearchHit | StoredDocSearchHit; children: React.ReactNode }) => JSX.Element;
|
||||
resultsFooterComponent?: (props: { state: AutocompleteState<InternalDocSearchHit> }) => JSX.Element | null;
|
||||
transformSearchClient?: <T extends LiteClient | SearchClient>(searchClient: T) => T;
|
||||
transformSearchClient?: (searchClient: DocSearchTransformClient) => DocSearchTransformClient;
|
||||
disableUserPersonalization?: boolean;
|
||||
initialQuery?: string;
|
||||
navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { liteClient } from 'algoliasearch/lite';
|
||||
import type { LiteClient } from 'algoliasearch/lite';
|
||||
import React from 'react';
|
||||
|
||||
import type { DocSearchTransformClient } from './DocSearch';
|
||||
import { version } from './version';
|
||||
|
||||
export function useSearchClient(
|
||||
appId: string,
|
||||
apiKey: string,
|
||||
transformSearchClient: (searchClient: LiteClient) => LiteClient,
|
||||
): LiteClient {
|
||||
transformSearchClient: (searchClient: DocSearchTransformClient) => DocSearchTransformClient,
|
||||
): DocSearchTransformClient {
|
||||
const searchClient = React.useMemo(() => {
|
||||
const client = liteClient(appId, apiKey);
|
||||
client.addAlgoliaAgent('docsearch', version);
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ See the [default implementation][8].
|
|||
|
||||
## `transformSearchClient`
|
||||
|
||||
> `type: function` | `default: searchClient => searchClient` | **optional**
|
||||
> `type: function` | `default: DocSearchTransformClient => DocSearchTransformClient` | **optional**
|
||||
|
||||
Useful for transforming the [Algolia Search Client][10], for example to [debounce search queries][9]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue