From 6f55a93a7f258604f08c896803a36adbf784b8b3 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Tue, 7 May 2024 10:38:24 -0700 Subject: [PATCH] Algolia result list pattern --- .../patterns/algolia-course-list.tsx | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/components/patterns/algolia-course-list.tsx diff --git a/src/components/patterns/algolia-course-list.tsx b/src/components/patterns/algolia-course-list.tsx new file mode 100644 index 00000000..af2155ee --- /dev/null +++ b/src/components/patterns/algolia-course-list.tsx @@ -0,0 +1,89 @@ +"use client"; + +import algoliasearch from "algoliasearch/lite"; +import {useHits,usePagination, Configure} from "react-instantsearch"; +import {InstantSearchNext} from "react-instantsearch-nextjs"; +import {useMemo} from "react"; +import {Hit as HitType} from "instantsearch.js"; + +type Props = { + appId: string + searchIndex: string + searchApiKey: string + itemUuids: string[] +} + +const AlgoliaCourseList = ({appId, searchIndex, searchApiKey, itemUuids}: Props) => { + const searchClient = useMemo(() => algoliasearch(appId, searchApiKey), [appId, searchApiKey]) + return ( + + `objectID:'${uuid}'`).join(" OR ")} + attributesToHighlight={["html"]} + attributesToSnippet={["html"]} + /> + + + ) +} + +const HitList = () => { + const {hits} = useHits({}); + const {currentRefinement: currentPage, pages, nbPages, refine: goToPage} = usePagination({padding: 2}) + + if (hits.length === 0) { + return ( +

No favorites at this time.

+ ) + } + + return ( +
+
    + {hits.map(hit => +
  • +
    + {hit.title} +
    +
  • + )} +
+ + {pages.length > 1 && + + } +
+ ) +} + +export default AlgoliaCourseList;