Skip to content

Commit

Permalink
Upgrade playgrounds to include keepZeroFacets and multi-index
Browse files Browse the repository at this point in the history
  • Loading branch information
bidoubiwa committed Dec 13, 2022
1 parent cd0f12c commit 63cc33a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/env/react/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { Routes, Route, Outlet } from 'react-router-dom'
import SingleIndex from './components/SingleIndex'
import MultiIndex from './components/MultiIndex'
import SingleMovieIndex from './components/SingleMovieIndex'

import './App.css'

Expand All @@ -11,6 +12,7 @@ const App = () => {
<Routes>
<Route path="/" element={<SingleIndex />} />
<Route path="multi-index" element={<MultiIndex />} />
<Route path="movie-index" element={<SingleMovieIndex />} />
</Routes>
<Outlet />
</div>
Expand Down
9 changes: 5 additions & 4 deletions tests/env/react/src/components/MultiIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {
Highlight,
RefinementList,
Index,
Hits,
InfiniteHits,
Pagination,
Hits,
} from 'react-instantsearch-dom'
import { instantMeiliSearch } from '../../../../../src/index'

const searchClient = instantMeiliSearch('http://localhost:7700', 'masterKey', {
primaryKey: 'id',
finitePagination: true,
keepZeroFacets: true,
})

const Hit = ({ hit }) => {
Expand All @@ -40,7 +42,7 @@ const MultiIndex = () => (
<h2 style={{ margin: 0 }}>Genres</h2>
<RefinementList attribute="genres" />
<h2 style={{ margin: 0 }}>Color</h2>
<RefinementList attribute="color" />
<RefinementList attribute="color" operator="and" />
<h2 style={{ margin: 0 }}>Platforms</h2>
<RefinementList attribute="platforms" />
</div>
Expand All @@ -62,9 +64,8 @@ const MultiIndex = () => (
<RefinementList attribute="platforms" />
</div>
<div className="right-panel">
<Hits hitComponent={Hit} />
<InfiniteHits hitComponent={Hit} />
</div>
<Pagination />
</div>
</Index>
</InstantSearch>
Expand Down
62 changes: 62 additions & 0 deletions tests/env/react/src/components/SingleMovieIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'instantsearch.css/themes/algolia-min.css'
import React from 'react'
import {
InstantSearch,
InfiniteHits,
SearchBox,
Stats,
Highlight,
ClearRefinements,
RefinementList,
} from 'react-instantsearch-dom'
import { instantMeiliSearch } from '../../../../../src/index'

const searchClient = instantMeiliSearch('http://localhost:7700', 'masterKey', {
primaryKey: 'id',
keepZeroFacets: true,
})

const SingleIndex = () => (
<div className="ais-InstantSearch">
<h1>Meilisearch + React InstantSearch</h1>
<h2>Search in movies</h2>

<InstantSearch indexName="movies" searchClient={searchClient}>
<Stats />
<div className="left-panel">
<ClearRefinements />
<h2>Genres</h2>
<RefinementList attribute="genres" />
<h2>Players</h2>
<RefinementList attribute="color" />
<h2>Platforms</h2>
<RefinementList attribute="platforms" />
</div>
<div className="right-panel">
<SearchBox />
<InfiniteHits hitComponent={Hit} />
</div>
</InstantSearch>
</div>
)

const Hit = ({ hit }) => {
return (
<div key={hit.id}>
<div className="hit-name">
<Highlight attribute="title" hit={hit} />
</div>
<div className="hit-name">
<Highlight attribute="genres" hit={hit} />
</div>
<div className="hit-name">
<Highlight attribute="color" hit={hit} />
</div>
<div className="hit-name">
<Highlight attribute="platforms" hit={hit} />
</div>
</div>
)
}

export default SingleIndex

0 comments on commit 63cc33a

Please sign in to comment.