-
Notifications
You must be signed in to change notification settings - Fork 531
/
Copy pathApp.tsx
112 lines (101 loc) · 2.61 KB
/
App.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { liteClient as algoliasearch } from 'algoliasearch/lite';
import { Hit } from 'instantsearch.js';
import React from 'react';
import {
Configure,
Highlight,
Hits,
InstantSearch,
Pagination,
RefinementList,
SearchBox,
TrendingItems,
Carousel,
} from 'react-instantsearch';
import { Panel } from './Panel';
import 'instantsearch.css/themes/satellite.css';
import './App.css';
const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);
export function App() {
return (
<div>
<header className="header">
<h1 className="header-title">
<a href="/">Getting started</a>
</h1>
<p className="header-subtitle">
using{' '}
<a href="https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch">
React InstantSearch
</a>
</p>
</header>
<div className="container">
<InstantSearch
searchClient={searchClient}
indexName="instant_search"
insights={true}
>
<Configure hitsPerPage={8} />
<div className="search-panel">
<div className="search-panel__filters">
<Panel header="brand">
<RefinementList attribute="brand" />
</Panel>
</div>
<div className="search-panel__results">
<SearchBox placeholder="" className="searchbox" />
<Hits hitComponent={HitComponent} />
<div className="pagination">
<Pagination />
</div>
<div>
<TrendingItems
itemComponent={ItemComponent}
limit={6}
layoutComponent={Carousel}
/>
</div>
</div>
</div>
</InstantSearch>
</div>
</div>
);
}
type HitType = Hit<{
image: string;
name: string;
description: string;
}>;
function HitComponent({ hit }: { hit: HitType }) {
return (
<article>
<h1>
<a href={`/products.html?pid=${hit.objectID}`}>
<Highlight attribute="name" hit={hit} />
</a>
</h1>
<p>
<Highlight attribute="description" hit={hit} />
</p>
<a href={`/products.html?pid=${hit.objectID}`}>See product</a>
</article>
);
}
function ItemComponent({ item }: { item: Hit }) {
return (
<div>
<article>
<div>
<img src={item.image} />
<h2>{item.name}</h2>
</div>
<a href={`/products.html?pid=${item.objectID}`}>See product</a>
</article>
</div>
);
}