Skip to content

Commit

Permalink
Merge pull request #731 from prezly/feature/add-get-search-client-util
Browse files Browse the repository at this point in the history
Feature - Add `getSearchClient` utility
  • Loading branch information
yuriyyakym authored Jul 23, 2024
2 parents d8ae2e0 + 2fc215c commit 549e1ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/nextjs/src/newsroom-context/hooks/useSearchClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { instantMeiliSearch } from '@meilisearch/instant-meilisearch';
import type { SearchSettings } from '@prezly/theme-kit-core/server';
import algoliasearch from 'algoliasearch/lite';
import { useMemo } from 'react';

import { getSearchClient } from '../utils';

export function useSearchClient(settings: SearchSettings) {
return settings.searchBackend === 'algolia'
? algoliasearch(settings.appId, settings.apiKey)
: instantMeiliSearch(settings.host, settings.apiKey).searchClient;
return useMemo(() => getSearchClient(settings), [settings]);
}
1 change: 1 addition & 0 deletions packages/nextjs/src/newsroom-context/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { NewsroomContext, NewsroomContextProvider, type NewsroomContextProps } from './context';
export * from './hooks';
export * from './utils';
9 changes: 9 additions & 0 deletions packages/nextjs/src/newsroom-context/utils/getSearchClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { instantMeiliSearch } from '@meilisearch/instant-meilisearch';
import type { SearchSettings } from '@prezly/theme-kit-core/server';
import algoliasearch from 'algoliasearch/lite';

export function getSearchClient(settings: SearchSettings) {
return settings.searchBackend === 'algolia'
? algoliasearch(settings.appId, settings.apiKey)
: instantMeiliSearch(settings.host, settings.apiKey).searchClient;
}
1 change: 1 addition & 0 deletions packages/nextjs/src/newsroom-context/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getSearchClient } from './getSearchClient';

0 comments on commit 549e1ca

Please sign in to comment.