From b8f41b5184f4387e026062f7982f04668681b92d Mon Sep 17 00:00:00 2001 From: Kevin Stadler Date: Mon, 2 Sep 2024 10:19:10 +0200 Subject: [PATCH] perf: move functions out of instantsearch function component --- app/instantsearch/instantsearch.tsx | 106 +++++++++++++++------------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/app/instantsearch/instantsearch.tsx b/app/instantsearch/instantsearch.tsx index 323687e..9ae4fd4 100644 --- a/app/instantsearch/instantsearch.tsx +++ b/app/instantsearch/instantsearch.tsx @@ -7,64 +7,70 @@ import TypesenseInstantSearchAdapter, { type SearchClient } from "typesense-inst import { ClickablePublicationThumbnail } from "@/components/publication-cover"; import type { Publication } from "@/types/model"; -export function InstantSearch() { - const t = useTranslations("SearchPage"); +const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({ + server: { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + apiKey: process.env.NEXT_PUBLIC_TYPESENSE_API_KEY!, + nodes: [ + { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + host: process.env.NEXT_PUBLIC_TYPESENSE_HOST!, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + port: Number(process.env.NEXT_PUBLIC_TYPESENSE_PORT!), + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + protocol: process.env.NEXT_PUBLIC_TYPESENSE_PROTOCOL!, + }, + ], + }, + // The following parameters are directly passed to Typesense's search API endpoint. + // So you can pass any parameters supported by the search endpoint below. + // queryBy is required. + additionalSearchParameters: { + query_by: "title", + }, +}); +// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment +const searchClient = typesenseInstantsearchAdapter.searchClient as unknown as SearchClient; - const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({ - server: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - apiKey: process.env.NEXT_PUBLIC_TYPESENSE_API_KEY!, - nodes: [ - { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - host: process.env.NEXT_PUBLIC_TYPESENSE_HOST!, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - port: Number(process.env.NEXT_PUBLIC_TYPESENSE_PORT!), - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - protocol: process.env.NEXT_PUBLIC_TYPESENSE_PROTOCOL!, - }, - ], - }, - // The following parameters are directly passed to Typesense's search API endpoint. - // So you can pass any parameters supported by the search endpoint below. - // queryBy is required. - additionalSearchParameters: { - query_by: "title", - }, - }); - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const searchClient = typesenseInstantsearchAdapter.searchClient as unknown as SearchClient; +function DefaultRefinementList({ + attribute, + placeholder, +}: { + attribute: string; + placeholder: string; +}) { + return ( + + ); +} - function DefaultRefinementList({ - attribute, - attributeName, - }: { - attribute: string; - attributeName: string; - }) { - return ( - - ); - } +export function InstantSearch() { + const t = useTranslations("SearchPage"); return ( // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- - - + + +