Commit 17d0440d authored by deb355529's avatar deb355529
Browse files

DEICH-5813: deichman.no: added option to add items to "huskeliste", also did a cleanup

parent 29bfba43
import React, { Component } from "react";
import React from "react";
import PropTypes from "prop-types";
import autoBind from "auto-bind";
import classNames from "classnames";
import Router, { withRouter } from "next/router";
......@@ -14,20 +13,28 @@ import { Container, Block, ShowMore, Loader } from "@digibib/deichman-ui";
import "./styles.css";
class SearchResults extends Component {
constructor() {
super();
autoBind(this);
}
const SearchResults = props => {
const {
query,
initialRender,
searchQuery,
results,
listMode,
favourites,
isSearching,
error,
onFavourite,
tracker,
router
} = props;
handleNextPage() {
const { query, router } = this.props;
const handleNextPage = () => {
const { pathname = "/", asPath = "/" } = router;
const newQueries = {
...query,
page: parseInt(query.page || 1, 10) + 1
};
this.props.tracker.loadMore(newQueries.page, this.props.searchQuery);
props.tracker.loadMore(newQueries.page, props.searchQuery);
// Delete searchQuery (should not appear in url as a query param, part of route)
delete newQueries.searchQuery;
......@@ -41,21 +48,7 @@ class SearchResults extends Component {
query: newQueries
}
);
}
render() {
const {
query,
initialRender,
searchQuery,
results,
listMode,
favourites,
isSearching,
error,
onFavourite,
tracker
} = this.props;
};
const { hits = [] } = results;
const noHits = hits.length < 1 && !isSearching;
......@@ -89,7 +82,7 @@ class SearchResults extends Component {
// If there's an error
if (error !== null) {
return <FullScreen>{error !== null && <p>En feil har oppstått</p>}</FullScreen>;
return <FullScreen>{<p>En feil har oppstått</p>}</FullScreen>;
}
const searchQuerySegments = getSearchQuerySegments(searchQuery);
......@@ -117,6 +110,7 @@ class SearchResults extends Component {
totalCount={results.totalHits}
favourites={favourites}
onFavourite={onFavourite}
showFavorite
/>
</Block>
......@@ -124,7 +118,7 @@ class SearchResults extends Component {
{canFetchMore && (
<ShowMore
text="Hent flere resultater"
onClick={this.handleNextPage}
onClick={handleNextPage}
disabled={isSearching}
/>
)}
......@@ -132,8 +126,7 @@ class SearchResults extends Component {
</Container>
</section>
);
}
}
};
SearchResults.defaultProps = {
query: {},
......@@ -159,7 +152,7 @@ SearchResults.propTypes = {
export default withRouter(SearchResults);
//---- Utils below ----
// ---- Utils below ----
function getSearchQuerySegments(searchQuery) {
const fieldExpression = RegExp('([^:\\s]+):\\s*"([^"]+)"', "g");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment