-
Notifications
You must be signed in to change notification settings - Fork 28k
/
Copy pathSearch.tsx
66 lines (59 loc) · 1.38 KB
/
Search.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use client";
import algoliasearch from "algoliasearch/lite";
import type { Hit as AlgoliaHit } from "instantsearch.js";
import React from "react";
import {
Configure,
Highlight,
Hits,
Pagination,
RefinementList,
SearchBox,
} from "react-instantsearch";
import { InstantSearchNext } from "react-instantsearch-nextjs";
import { Panel } from "./Panel";
type HitProps = {
hit: AlgoliaHit<{
name: string;
description: string;
price: number;
}>;
};
const APP_ID = "latency";
const API_KEY = "6be0576ff61c053d5f9a3225e2a90f76";
const INDEX_NAME = "instant_search";
const searchClient = algoliasearch(APP_ID, API_KEY);
function Hit({ hit }: HitProps) {
return (
<>
<Highlight hit={hit} attribute="name" className="Hit-label" />
<span className="Hit-price">${hit.price}</span>
</>
);
}
export default function Search() {
return (
<InstantSearchNext
searchClient={searchClient}
indexName={INDEX_NAME}
routing
future={{
preserveSharedStateOnUnmount: true,
}}
>
<Configure hitsPerPage={12} />
<main>
<div>
<Panel header="Brands">
<RefinementList attribute="brand" showMore />
</Panel>
</div>
<div>
<SearchBox />
<Hits hitComponent={Hit} />
<Pagination />
</div>
</main>
</InstantSearchNext>
);
}