Prevent duplicate load of favourites (tootsuite pr #5931)

This commit is contained in:
cwm
2018-01-09 08:46:35 -06:00
parent ce7f4aef16
commit 5963630c63
3 changed files with 24 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/col
import StatusList from 'flavours/glitch/components/status_list';
import { defineMessages, injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { debounce } from 'lodash';
const messages = defineMessages({
heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
@ -16,6 +17,7 @@ const messages = defineMessages({
const mapStateToProps = state => ({
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
});
@ -30,6 +32,7 @@ export default class Favourites extends ImmutablePureComponent {
columnId: PropTypes.string,
multiColumn: PropTypes.bool,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
};
componentWillMount () {
@ -59,12 +62,12 @@ export default class Favourites extends ImmutablePureComponent {
this.column = c;
}
handleScrollToBottom = () => {
handleScrollToBottom = debounce(() => {
this.props.dispatch(expandFavouritedStatuses());
}
}, 300, { leading: true })
render () {
const { intl, statusIds, columnId, multiColumn, hasMore } = this.props;
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
const pinned = !!columnId;
return (
@ -85,6 +88,7 @@ export default class Favourites extends ImmutablePureComponent {
statusIds={statusIds}
scrollKey={`favourited_statuses-${columnId}`}
hasMore={hasMore}
isLoading={isLoading}
onScrollToBottom={this.handleScrollToBottom}
/>
</Column>