From 0c5ebe5219e70abcca6ae83f647f3ab23fe18420 Mon Sep 17 00:00:00 2001
From: esikkala <esko.ikkala@aalto.fi>
Date: Wed, 27 Feb 2019 14:03:59 +0200
Subject: [PATCH] Add separate history object

---
 src/client/components/History.js     |  3 +++
 src/client/components/ResultTable.js | 15 +++++++--------
 src/client/index.js                  |  4 ++--
 3 files changed, 12 insertions(+), 10 deletions(-)
 create mode 100644 src/client/components/History.js

diff --git a/src/client/components/History.js b/src/client/components/History.js
new file mode 100644
index 00000000..9937105a
--- /dev/null
+++ b/src/client/components/History.js
@@ -0,0 +1,3 @@
+import { createBrowserHistory } from 'history';
+
+export default createBrowserHistory();
diff --git a/src/client/components/ResultTable.js b/src/client/components/ResultTable.js
index 8613615c..bad33dde 100644
--- a/src/client/components/ResultTable.js
+++ b/src/client/components/ResultTable.js
@@ -10,6 +10,7 @@ import CircularProgress from '@material-ui/core/CircularProgress';
 import purple from '@material-ui/core/colors/purple';
 import ResultTableHead from './ResultTableHead';
 import { parse } from 'query-string';
+import history from './History';
 
 const styles = () => ({
   tableContainer: {
@@ -44,13 +45,8 @@ class ResultTable extends React.Component {
     let page;
     if (this.props.routeProps.location.search === '') {
       page = this.props.data.page === -1 ? 0 : this.props.data.page;
-      this.props.routeProps.history.push({
-        pathname: `/${this.props.resultClass}/table`,
-        data: `?page=${this.props.data.page}`,
-      });
-      //console.log(`result table mounted WITHOUT page parameter, set page to ${page}`);
+      // console.log(`result table mounted WITHOUT page parameter, set page to ${page}`);
     } else {
-      //console.log(this.props.routeProps.location.data)
       page = parseInt(parse(this.props.routeProps.location.search).page);
       // console.log(`result table mounted with page parameter, set page to ${page}`);
     }
@@ -60,13 +56,16 @@ class ResultTable extends React.Component {
   componentDidUpdate = prevProps => {
     if (prevProps.data.page != this.props.data.page) {
       this.props.fetchPaginatedResults(this.props.resultClass, this.props.facetClass, this.props.variant);
-      this.props.routeProps.history.push({
+      // console.log('push to history')
+      // console.log(this.props.data.page)
+      history.push({
         pathname: `/${this.props.resultClass}/table`,
-        data: `?page=${this.props.data.page}`,
+        search: `?page=${this.props.data.page}`,
       });
     }
     if (prevProps.filters != this.props.filters) {
       this.props.updatePage(this.props.resultClass, 0);
+      // if already on page 0, fetch results
       if (this.props.data.page == 0) {
         this.props.fetchPaginatedResults(this.props.resultClass, this.props.facetClass, this.props.variant);
       }
diff --git a/src/client/index.js b/src/client/index.js
index 855e54b0..fe1caedb 100644
--- a/src/client/index.js
+++ b/src/client/index.js
@@ -6,7 +6,7 @@ import {responsiveStoreEnhancer} from 'redux-responsive';
 import { Provider } from 'react-redux';
 import ReduxToastr, { actions as toastrActions } from 'react-redux-toastr';
 import { Router } from 'react-router-dom';
-import { createBrowserHistory } from 'history';
+import history from './components/History';
 import 'react-redux-toastr/lib/css/react-redux-toastr.min.css';
 import 'react-virtualized/styles.css';
 
@@ -15,7 +15,7 @@ import rootEpic from './epics';
 import App from './components/App';
 
 const epicMiddleware = createEpicMiddleware();
-const history = createBrowserHistory();
+
 
 const store = createStore(
   reducer,
-- 
GitLab