-
Notifications
You must be signed in to change notification settings - Fork 551
Expand file tree
/
Copy pathApp.tsx
More file actions
122 lines (110 loc) · 2.88 KB
/
App.tsx
File metadata and controls
122 lines (110 loc) · 2.88 KB
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
113
114
115
116
117
118
119
120
121
122
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,
Chat,
} 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>
<Chat
agentId="92a0b174-344c-4b0c-bde8-90b5d221f2b3"
itemComponent={ItemComponent}
/>
</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 (
<article className="ais-Carousel-hit">
<div className="ais-Carousel-hit-image">
<img src={item.image} />
</div>
<h2 className="ais-Carousel-hit-title">
<a
href={`/products.html?pid=${item.objectID}`}
className="ais-Carousel-hit-link"
>
{item.name}
</a>
</h2>
</article>
);
}