@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
66 lines (53 loc) • 2.7 kB
JavaScript
var _class, _temp;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React from 'react';
import PropTypes from 'prop-types';
import Pager from './Pager';
/**
* A Searcher-aware wrapper around the Pager component that triggers the Searcher to return the
* next/previous page of search results.
*/
var SearchResultsPager = (_temp = _class = function (_React$Component) {
_inherits(SearchResultsPager, _React$Component);
function SearchResultsPager(props) {
_classCallCheck(this, SearchResultsPager);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.changePage = _this.changePage.bind(_this);
return _this;
}
SearchResultsPager.prototype.changePage = function changePage(newPage) {
var searcher = this.context.searcher;
if (searcher) {
searcher.changePage(newPage);
}
};
SearchResultsPager.prototype.render = function render() {
var searcher = this.context.searcher;
if (searcher) {
if (searcher.state.response) {
var pageSize = searcher.state.resultsPerPage;
if (pageSize > 0) {
var currentPage = Math.floor(searcher.state.resultsOffset / pageSize);
var totalHits = searcher.state.response.totalHits;
var numPages = Math.ceil(totalHits / pageSize);
return React.createElement(Pager, {
onPageChange: this.changePage,
currentPage: currentPage,
totalPages: numPages,
right: this.props.right
});
}
}
}
// No searcher or no results... return nothing;
return null;
};
return SearchResultsPager;
}(React.Component), _class.defaultProps = {
right: false
}, _class.contextTypes = {
searcher: PropTypes.any
}, _class.displayName = 'SearchResultsPager', _temp);
export { SearchResultsPager as default };