Skip to content

Commit 290371a

Browse files
committed
Upgrade playgrounds to include keepZeroFacets and multi-index
1 parent 1f7170d commit 290371a

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

tests/env/react/src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import { Routes, Route, Outlet } from 'react-router-dom'
33
import SingleIndex from './components/SingleIndex'
44
import MultiIndex from './components/MultiIndex'
5+
import SingleMovieIndex from './components/SingleMovieIndex'
56

67
import './App.css'
78

@@ -11,6 +12,7 @@ const App = () => {
1112
<Routes>
1213
<Route path="/" element={<SingleIndex />} />
1314
<Route path="multi-index" element={<MultiIndex />} />
15+
<Route path="movie-index" element={<SingleMovieIndex />} />
1416
</Routes>
1517
<Outlet />
1618
</div>

tests/env/react/src/components/MultiIndex.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import {
66
Highlight,
77
RefinementList,
88
Index,
9-
Hits,
9+
InfiniteHits,
1010
Pagination,
11+
Hits,
1112
} from 'react-instantsearch-dom'
1213
import { instantMeiliSearch } from '../../../../../src/index'
1314

1415
const searchClient = instantMeiliSearch('http://localhost:7700', 'masterKey', {
1516
primaryKey: 'id',
1617
finitePagination: true,
18+
keepZeroFacets: true,
1719
})
1820

1921
const Hit = ({ hit }) => {
@@ -40,7 +42,7 @@ const MultiIndex = () => (
4042
<h2 style={{ margin: 0 }}>Genres</h2>
4143
<RefinementList attribute="genres" />
4244
<h2 style={{ margin: 0 }}>Color</h2>
43-
<RefinementList attribute="color" />
45+
<RefinementList attribute="color" operator="and" />
4446
<h2 style={{ margin: 0 }}>Platforms</h2>
4547
<RefinementList attribute="platforms" />
4648
</div>
@@ -62,9 +64,8 @@ const MultiIndex = () => (
6264
<RefinementList attribute="platforms" />
6365
</div>
6466
<div className="right-panel">
65-
<Hits hitComponent={Hit} />
67+
<InfiniteHits hitComponent={Hit} />
6668
</div>
67-
<Pagination />
6869
</div>
6970
</Index>
7071
</InstantSearch>

tests/env/react/src/components/SingleIndex.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'instantsearch.css/themes/algolia-min.css'
22
import React from 'react'
33
import {
44
InstantSearch,
5-
InfiniteHits,
65
SearchBox,
76
Stats,
87
Highlight,
@@ -11,11 +10,16 @@ import {
1110
Configure,
1211
SortBy,
1312
Snippet,
13+
Pagination,
14+
Hits,
1415
} from 'react-instantsearch-dom'
1516
import { instantMeiliSearch } from '../../../../../src/index'
1617

1718
const searchClient = instantMeiliSearch('http://localhost:7700', 'masterKey', {
1819
primaryKey: 'id',
20+
placeholderSearch: false,
21+
finitePagination: true,
22+
keepZeroFacets: true,
1923
})
2024

2125
const SingleIndex = () => (
@@ -58,14 +62,15 @@ const SingleIndex = () => (
5862
<h2>Misc</h2>
5963
<RefinementList attribute="misc" />
6064
<Configure
61-
hitsPerPage={6}
65+
hitsPerPage={4}
6266
attributesToSnippet={['description:50']}
6367
snippetEllipsisText={'...'}
6468
/>
6569
</div>
6670
<div className="right-panel">
6771
<SearchBox />
68-
<InfiniteHits hitComponent={Hit} />
72+
<Hits hitComponent={Hit} />
73+
<Pagination />
6974
</div>
7075
</InstantSearch>
7176
</div>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'instantsearch.css/themes/algolia-min.css'
2+
import React from 'react'
3+
import {
4+
InstantSearch,
5+
InfiniteHits,
6+
SearchBox,
7+
Stats,
8+
Highlight,
9+
ClearRefinements,
10+
RefinementList,
11+
} from 'react-instantsearch-dom'
12+
import { instantMeiliSearch } from '../../../../../src/index'
13+
14+
const searchClient = instantMeiliSearch('http://localhost:7700', 'masterKey', {
15+
primaryKey: 'id',
16+
keepZeroFacets: true,
17+
})
18+
19+
const SingleIndex = () => (
20+
<div className="ais-InstantSearch">
21+
<h1>Meilisearch + React InstantSearch</h1>
22+
<h2>Search in movies</h2>
23+
24+
<InstantSearch indexName="movies" searchClient={searchClient}>
25+
<Stats />
26+
<div className="left-panel">
27+
<ClearRefinements />
28+
<h2>Genres</h2>
29+
<RefinementList attribute="genres" />
30+
<h2>Players</h2>
31+
<RefinementList attribute="color" />
32+
<h2>Platforms</h2>
33+
<RefinementList attribute="platforms" />
34+
</div>
35+
<div className="right-panel">
36+
<SearchBox />
37+
<InfiniteHits hitComponent={Hit} />
38+
</div>
39+
</InstantSearch>
40+
</div>
41+
)
42+
43+
const Hit = ({ hit }) => {
44+
return (
45+
<div key={hit.id}>
46+
<div className="hit-name">
47+
<Highlight attribute="title" hit={hit} />
48+
</div>
49+
<div className="hit-name">
50+
<Highlight attribute="genres" hit={hit} />
51+
</div>
52+
<div className="hit-name">
53+
<Highlight attribute="color" hit={hit} />
54+
</div>
55+
<div className="hit-name">
56+
<Highlight attribute="platforms" hit={hit} />
57+
</div>
58+
</div>
59+
)
60+
}
61+
62+
export default SingleIndex

0 commit comments

Comments
 (0)