Allow endless scrolling of moderation log

This commit is contained in:
Alex Gleason 2021-03-15 17:54:48 -05:00
parent c6b7a7ca8a
commit 9156e01862
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 16 additions and 1 deletions

View File

@ -15,6 +15,7 @@ const messages = defineMessages({
const mapStateToProps = state => ({ const mapStateToProps = state => ({
items: state.getIn(['admin_log', 'index']).map(i => state.getIn(['admin_log', 'items', String(i)])), items: state.getIn(['admin_log', 'index']).map(i => state.getIn(['admin_log', 'items', String(i)])),
hasMore: state.getIn(['admin_log', 'total'], 0) - state.getIn(['admin_log', 'index']).count() > 0,
}); });
export default @connect(mapStateToProps) export default @connect(mapStateToProps)
@ -41,8 +42,20 @@ class ModerationLog extends ImmutablePureComponent {
.catch(() => {}); .catch(() => {});
} }
handleLoadMore = () => {
const page = this.state.lastPage + 1;
this.setState({ isLoading: true });
this.props.dispatch(fetchModerationLog({ page }))
.then(data => this.setState({
isLoading: false,
lastPage: page,
}))
.catch(() => {});
}
render() { render() {
const { intl, items } = this.props; const { intl, items, hasMore } = this.props;
const { isLoading } = this.state; const { isLoading } = this.state;
const showLoading = isLoading && items.count() === 0; const showLoading = isLoading && items.count() === 0;
@ -53,6 +66,8 @@ class ModerationLog extends ImmutablePureComponent {
showLoading={showLoading} showLoading={showLoading}
scrollKey='moderation-log' scrollKey='moderation-log'
emptyMessage={intl.formatMessage(messages.emptyMessage)} emptyMessage={intl.formatMessage(messages.emptyMessage)}
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
> >
{items.map((item, i) => ( {items.map((item, i) => (
<div className='logentry' key={i}> <div className='logentry' key={i}>