2017-07-12 20:00:47 +02:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import {
|
|
|
|
RefinementList,
|
|
|
|
SearchBox,
|
|
|
|
Hits,
|
|
|
|
Configure,
|
|
|
|
Highlight,
|
2019-11-11 04:24:53 +01:00
|
|
|
Pagination,
|
2020-06-19 02:23:02 +02:00
|
|
|
InstantSearch,
|
|
|
|
} from 'react-instantsearch-dom'
|
|
|
|
import { indexName, searchClient } from './instantsearch'
|
2017-07-12 20:00:47 +02:00
|
|
|
|
2018-12-17 17:34:32 +01:00
|
|
|
const HitComponent = ({ hit }) => (
|
2019-11-11 04:24:53 +01:00
|
|
|
<div className="hit">
|
2017-07-12 20:00:47 +02:00
|
|
|
<div>
|
2019-11-11 04:24:53 +01:00
|
|
|
<div className="hit-picture">
|
2017-07-12 20:00:47 +02:00
|
|
|
<img src={`${hit.image}`} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-11 04:24:53 +01:00
|
|
|
<div className="hit-content">
|
2017-07-12 20:00:47 +02:00
|
|
|
<div>
|
2020-06-19 02:23:02 +02:00
|
|
|
<Highlight attribute="name" hit={hit} />
|
2018-12-17 17:34:32 +01:00
|
|
|
<span> - ${hit.price}</span>
|
|
|
|
<span> - {hit.rating} stars</span>
|
2017-07-12 20:00:47 +02:00
|
|
|
</div>
|
2019-11-11 04:24:53 +01:00
|
|
|
<div className="hit-type">
|
2020-06-19 02:23:02 +02:00
|
|
|
<Highlight attribute="type" hit={hit} />
|
2017-07-12 20:00:47 +02:00
|
|
|
</div>
|
2019-11-11 04:24:53 +01:00
|
|
|
<div className="hit-description">
|
2020-06-19 02:23:02 +02:00
|
|
|
<Highlight attribute="description" hit={hit} />
|
2017-07-12 20:00:47 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-12-17 17:34:32 +01:00
|
|
|
)
|
2017-07-12 20:00:47 +02:00
|
|
|
|
|
|
|
HitComponent.propTypes = {
|
2019-11-11 04:24:53 +01:00
|
|
|
hit: PropTypes.object,
|
2017-07-12 20:00:47 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 23:44:18 +02:00
|
|
|
export default class App extends React.Component {
|
2017-07-12 20:00:47 +02:00
|
|
|
static propTypes = {
|
|
|
|
searchState: PropTypes.object,
|
|
|
|
resultsState: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
2019-11-11 04:24:53 +01:00
|
|
|
onSearchStateChange: PropTypes.func,
|
2018-12-17 17:34:32 +01:00
|
|
|
}
|
2017-07-12 20:00:47 +02:00
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
render() {
|
2017-07-12 20:00:47 +02:00
|
|
|
return (
|
|
|
|
<InstantSearch
|
2020-06-19 02:23:02 +02:00
|
|
|
indexName={indexName}
|
|
|
|
searchClient={searchClient}
|
2017-07-12 20:00:47 +02:00
|
|
|
resultsState={this.props.resultsState}
|
|
|
|
onSearchStateChange={this.props.onSearchStateChange}
|
|
|
|
searchState={this.props.searchState}
|
|
|
|
>
|
|
|
|
<Configure hitsPerPage={10} />
|
|
|
|
<header>
|
|
|
|
<h1>React InstantSearch + Next.Js</h1>
|
|
|
|
<SearchBox />
|
|
|
|
</header>
|
|
|
|
<content>
|
|
|
|
<menu>
|
2020-06-19 02:23:02 +02:00
|
|
|
<RefinementList attribute="category" />
|
2017-07-12 20:00:47 +02:00
|
|
|
</menu>
|
2020-06-19 02:23:02 +02:00
|
|
|
<Hits hitComponent={HitComponent} />
|
2017-07-12 20:00:47 +02:00
|
|
|
</content>
|
|
|
|
<footer>
|
|
|
|
<Pagination />
|
|
|
|
<div>
|
|
|
|
See{' '}
|
2019-11-11 04:24:53 +01:00
|
|
|
<a href="https://github.com/algolia/react-instantsearch/tree/master/packages/react-instantsearch/examples/next-app">
|
2017-07-12 20:00:47 +02:00
|
|
|
source code
|
|
|
|
</a>{' '}
|
|
|
|
on github
|
|
|
|
</div>
|
|
|
|
</footer>
|
|
|
|
</InstantSearch>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|