Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix infinite scrolling for collections with integrations #940

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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