From 550367d12f23c097e36680d7f0edc9d802bb5b04 Mon Sep 17 00:00:00 2001 From: Alice Dahan Date: Tue, 23 Jul 2024 18:24:51 +0200 Subject: [PATCH] =?UTF-8?q?refactor(recherche):=20Factorise=20le=20client?= =?UTF-8?q?=20et=20l'index=20Algolia=20utilis=C3=A9=20pour=20les=20recherc?= =?UTF-8?q?hes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/source/components/search/Algolia.ts | 9 +++++++++ site/source/components/search/SearchRules.tsx | 10 ++-------- .../components/search/SearchRulesAndSimulators.tsx | 14 ++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) create mode 100644 site/source/components/search/Algolia.ts diff --git a/site/source/components/search/Algolia.ts b/site/source/components/search/Algolia.ts new file mode 100644 index 000000000..31d936b89 --- /dev/null +++ b/site/source/components/search/Algolia.ts @@ -0,0 +1,9 @@ +import algoliasearch from 'algoliasearch/lite' + +const ALGOLIA_APP_ID = import.meta.env.VITE_ALGOLIA_APP_ID || '' +const ALGOLIA_SEARCH_KEY = import.meta.env.VITE_ALGOLIA_SEARCH_KEY || '' + +export const searchClient = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_SEARCH_KEY) + +export const algoliaIndexPrefix = + import.meta.env.VITE_ALGOLIA_INDEX_PREFIX || '' diff --git a/site/source/components/search/SearchRules.tsx b/site/source/components/search/SearchRules.tsx index dc7fec360..00bdefedf 100644 --- a/site/source/components/search/SearchRules.tsx +++ b/site/source/components/search/SearchRules.tsx @@ -1,24 +1,18 @@ -import algoliasearch from 'algoliasearch/lite' import { Trans, useTranslation } from 'react-i18next' import { H2 } from '@/design-system/typography/heading' +import { algoliaIndexPrefix, searchClient } from './Algolia' import { RulesInfiniteHits } from './RulesInfiniteHits' import { SearchBox } from './SearchBox' import { SearchRoot } from './SearchRoot' -const ALGOLIA_APP_ID = import.meta.env.VITE_ALGOLIA_APP_ID || '' -const ALGOLIA_SEARCH_KEY = import.meta.env.VITE_ALGOLIA_SEARCH_KEY || '' -const ALGOLIA_INDEX_PREFIX = import.meta.env.VITE_ALGOLIA_INDEX_PREFIX || '' - -const searchClient = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_SEARCH_KEY) - export default function SearchRules() { const { t } = useTranslation() return ( void } @@ -36,7 +30,7 @@ export default function SearchRulesAndSimulators({ closePopover }: Props) { return ( @@ -45,12 +39,12 @@ export default function SearchRulesAndSimulators({ closePopover }: Props) { aria-label={t('Rechercher un simulateur ou une règle')} /> - + - +