|
1 | 1 | "use client"; |
2 | 2 |
|
3 | 3 | import React, { Suspense } from "react"; |
4 | | -import { useSearchParams } from "next/navigation"; |
5 | 4 | import { useGridLayout } from "@/hooks/useGridLayout"; |
6 | 5 | import { LoadingSkeleton } from "@/components/LoadingSkeleton"; |
7 | 6 | import { ApiGrid } from "@/components/ApiGrid"; |
8 | 7 | import { liteClient as algoliasearch } from "algoliasearch/lite"; |
9 | 8 | import { InstantSearch } from "react-instantsearch"; |
10 | 9 | import { SearchSection } from "@/components/SearchSection"; |
| 10 | +import { history } from "instantsearch.js/es/lib/routers"; |
11 | 11 |
|
12 | 12 | const searchClient = algoliasearch( |
13 | 13 | "D29MLR0AMY", |
14 | | - "03da9918f8ebfdb40e9b37cfd43ed8c4", |
| 14 | + "03da9918f8ebfdb40e9b37cfd43ed8c4" |
15 | 15 | ); |
16 | 16 |
|
| 17 | +const indexName = "prod_apis_guru"; |
| 18 | + |
| 19 | +const routing = { |
| 20 | + router: history(), |
| 21 | + stateMapping: { |
| 22 | + stateToRoute(uiState: any) { |
| 23 | + const indexUiState = uiState[indexName] || {}; |
| 24 | + return { |
| 25 | + query: indexUiState.query || undefined, |
| 26 | + }; |
| 27 | + }, |
| 28 | + routeToState(routeState: any) { |
| 29 | + return { |
| 30 | + [indexName]: { |
| 31 | + query: routeState.query || "", |
| 32 | + }, |
| 33 | + }; |
| 34 | + }, |
| 35 | + }, |
| 36 | +}; |
| 37 | + |
17 | 38 | interface SearchClientComponentProps { |
18 | 39 | providerSlug?: string; |
19 | 40 | } |
20 | 41 |
|
21 | 42 | function SearchClientComponentInner({ |
22 | 43 | providerSlug, |
23 | 44 | }: SearchClientComponentProps) { |
24 | | - const searchParams = useSearchParams(); |
25 | | - const initialSearchTerm = searchParams?.get("q") || ""; |
26 | | - const initialCombinedSearchTerm = providerSlug |
27 | | - ? `${providerSlug} ${initialSearchTerm}`.trim() |
28 | | - : initialSearchTerm; |
29 | | - |
30 | 45 | const { gridColumns, pageSize } = useGridLayout(); |
31 | 46 |
|
32 | 47 | return ( |
33 | 48 | <div className="container mx-auto px-4 relative"> |
34 | 49 | <div className="relative z-10"> |
35 | 50 | <InstantSearch |
36 | | - indexName="prod_apis_guru" |
| 51 | + indexName={indexName} |
37 | 52 | searchClient={searchClient} |
38 | | - initialUiState={{ |
39 | | - prod_apis_guru: { |
40 | | - query: initialCombinedSearchTerm, |
41 | | - sortBy: "prod_apis_guru_by_name_asc", |
42 | | - }, |
43 | | - }} |
| 53 | + routing={routing} |
44 | 54 | > |
45 | 55 | <SearchSection /> |
46 | 56 |
|
|
0 commit comments