Skip to content
Snippets Groups Projects
Commit 118fcc0c authored by esikkala's avatar esikkala
Browse files

Improve result table lifecycle handling

parent 53ee0e4e
No related branches found
No related tags found
No related merge requests found
......@@ -65,29 +65,42 @@ class ResultTable extends React.Component {
let page;
if (this.props.routeProps.location.search === '') {
page = this.props.page === -1 ? 0 : this.props.page;
this.props.routeProps.history.replace({
this.props.routeProps.history.push({
pathname: '/manuscripts/table',
search: `?page=${page}`,
search: `?page=${this.props.page}`,
});
//console.log(`result table mounted WITHOUT page parameter, set page to ${page}`);
} else {
//console.log(this.props.routeProps.location.search)
page = parseInt(parse(this.props.routeProps.location.search).page);
// console.log(`result table mounted with page parameter, set page to ${page}`);
}
this.props.updatePage(page);
// console.log('mounted, fetching manuscripts')
this.props.fetchManuscripts();
}
componentDidUpdate = prevProps => {
if (prevProps.page != this.props.page) {
// console.log(`previous page: ${prevProps.page}`)
// console.log(`page updated to ${this.props.page}, fetch manuscripts`)
this.props.fetchManuscripts();
this.props.routeProps.history.push({
pathname: '/manuscripts/table',
search: `?page=${this.props.page}`,
});
}
if (prevProps.facetFilters != this.props.facetFilters) {
// console.log('filters updated')
// console.log('filters updated, to page 0')
this.props.updatePage(0);
this.props.fetchManuscripts();
if (this.props.page == 0) {
this.props.fetchManuscripts();
}
}
}
handleChangePage = (event, page) => {
if (event != null) {
this.props.updatePage(page);
}
}
......@@ -254,7 +267,7 @@ class ResultTable extends React.Component {
<Table className={classes.table}>
<ResultTableHead
fetchManuscripts={this.props.fetchManuscripts}
updatePage={this.props.updatePage}
onChangePage={this.handleChangePage}
resultCount={this.props.resultCount}
page={this.props.page}
routeProps={this.props.routeProps}
......
......@@ -78,11 +78,6 @@ class ResultTableHead extends React.Component {
orderBy: 'productionPlace',
};
handleChangePage = (event, page) => {
this.props.updatePage(page);
this.props.fetchManuscripts();
};
handleChangeRowsPerPage = event => {
this.setState({ rowsPerPage: event.target.value });
};
......@@ -121,7 +116,7 @@ class ResultTableHead extends React.Component {
rowsPerPage={rowsPerPage}
rowsPerPageOptions={[5]}
page={page}
onChangePage={this.handleChangePage}
onChangePage={this.props.onChangePage}
onChangeRowsPerPage={this.handleChangeRowsPerPage}
ActionsComponent={ResultTablePaginationActions}
classes={{root: classes.paginationRoot}}
......@@ -147,7 +142,7 @@ ResultTableHead.propTypes = {
classes: PropTypes.object.isRequired,
resultCount: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
updatePage: PropTypes.func.isRequired,
onChangePage: PropTypes.func.isRequired,
fetchManuscripts: PropTypes.func.isRequired,
routeProps: PropTypes.object.isRequired,
};
......
......@@ -77,7 +77,7 @@ let MapApp = (props) => {
const { classes } = props;
// browser
// error,
console.log(props.search)
///console.log(props.search)
return (
<div className={classes.root}>
<div className={classes.appFrame}>
......
......@@ -87,8 +87,8 @@ const search = (state = INITIAL_STATE, action) => {
fetchingSuggestions: false
};
case UPDATE_MANUSCRIPTS:
console.log('updating manuscripts:');
console.log(action);
// console.log('updating manuscripts in reducer:');
// console.log(action);
return {
...state,
manuscriptCount: parseInt(action.data.manuscriptCount),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment