Skip to content

Commit

Permalink
fix infinite scrolling for collections with integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Dec 19, 2017
1 parent 11ee874 commit 4721f12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions src/components/Collection/Entries/EntriesCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,49 @@ import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
import { loadEntries } from 'Actions/entries';
import { loadEntries as actionLoadEntries } from 'Actions/entries';
import { selectEntries } from 'Reducers';
import Entries from './Entries';

class EntriesCollection extends React.Component {
static propTypes = {
collection: ImmutablePropTypes.map.isRequired,
publicFolder: PropTypes.string.isRequired,
dispatch: PropTypes.func.isRequired,
page: PropTypes.number,
entries: ImmutablePropTypes.list,
isFetching: PropTypes.bool.isRequired,
viewStyle: PropTypes.string,
};

componentDidMount() {
const { collection, dispatch } = this.props;
const { collection, loadEntries } = this.props;
if (collection) {
dispatch(loadEntries(collection));
loadEntries(collection);
}
}

componentWillReceiveProps(nextProps) {
const { collection, dispatch } = this.props;
const { collection, loadEntries } = this.props;
if (nextProps.collection !== collection) {
dispatch(loadEntries(nextProps.collection));
loadEntries(nextProps.collection);
}
}

handleLoadMore = page => {
const { collection, loadEntries } = this.props;
loadEntries(collection, page);
}

render () {
const { dispatch, collection, entries, publicFolder, page, isFetching, viewStyle } = this.props;
const { collection, entries, publicFolder, page, isFetching, viewStyle } = this.props;

return (
<Entries
collections={collection}
entries={entries}
publicFolder={publicFolder}
page={page}
onPaginate={() => dispatch(loadEntries(collection, page))}
onPaginate={this.handleLoadMore}
isFetching={isFetching}
collectionName={collection.get('label')}
viewStyle={viewStyle}
Expand All @@ -61,4 +65,8 @@ function mapStateToProps(state, ownProps) {
return { publicFolder, collection, page, entries, isFetching, viewStyle };
}

export default connect(mapStateToProps)(EntriesCollection);
const mapDispatchToProps = {
loadEntries: actionLoadEntries,
};

export default connect(mapStateToProps, mapDispatchToProps)(EntriesCollection);
2 changes: 1 addition & 1 deletion src/components/Collection/Entries/EntriesSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EntriesSearch extends React.Component {
};

render () {
const { dispatch, collections, entries, publicFolder, page, isFetching } = this.props;
const { collections, entries, publicFolder, page, isFetching } = this.props;
return (
<Entries
collections={collections}
Expand Down

0 comments on commit 4721f12

Please sign in to comment.