Improve infinite scroll on notifications

This commit is contained in:
Eugen Rochko 2017-01-26 04:30:40 +01:00
parent 57f7cf8349
commit 905c829179
7 changed files with 40 additions and 17 deletions

View file

@ -20,7 +20,8 @@ const getNotifications = createSelector([
], (excludedTypes, notifications) => notifications.filterNot(item => excludedTypes.includes(item.get('type'))));
const mapStateToProps = state => ({
notifications: getNotifications(state)
notifications: getNotifications(state),
isLoading: state.getIn(['notifications', 'isLoading'], true)
});
const Notifications = React.createClass({
@ -29,7 +30,8 @@ const Notifications = React.createClass({
notifications: ImmutablePropTypes.list.isRequired,
dispatch: React.PropTypes.func.isRequired,
trackScroll: React.PropTypes.bool,
intl: React.PropTypes.object.isRequired
intl: React.PropTypes.object.isRequired,
isLoading: React.PropTypes.bool
},
getDefaultProps () {
@ -42,8 +44,9 @@ const Notifications = React.createClass({
handleScroll (e) {
const { scrollTop, scrollHeight, clientHeight } = e.target;
const offset = scrollHeight - scrollTop - clientHeight;
if (scrollTop === scrollHeight - clientHeight) {
if (250 > offset && !this.props.isLoading) {
this.props.dispatch(expandNotifications());
}
},