bigbuffet-rw/app/soapbox/features/admin/moderation_log.js

94 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-01-01 10:50:13 -08:00
import React from 'react';
2021-03-15 16:17:00 -07:00
import { defineMessages, injectIntl, FormattedDate } from 'react-intl';
2021-01-01 10:50:13 -08:00
import { connect } from 'react-redux';
2021-03-15 15:29:48 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
2021-01-01 10:50:13 -08:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types';
import Column from '../ui/components/column';
import ScrollableList from 'soapbox/components/scrollable_list';
import { fetchModerationLog } from 'soapbox/actions/admin';
const messages = defineMessages({
heading: { id: 'column.admin.moderation_log', defaultMessage: 'Moderation Log' },
emptyMessage: { id: 'admin.moderation_log.empty_message', defaultMessage: 'You have not performed any moderation actions yet. When you do, a history will be shown here.' },
});
2021-03-15 15:29:48 -07:00
const mapStateToProps = state => ({
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,
2021-03-15 15:29:48 -07:00
});
export default @connect(mapStateToProps)
2021-01-01 10:50:13 -08:00
@injectIntl
class ModerationLog extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
2021-03-15 15:29:48 -07:00
list: ImmutablePropTypes.list,
2021-01-01 10:50:13 -08:00
};
state = {
isLoading: true,
2021-03-15 15:29:48 -07:00
lastPage: 0,
2021-01-01 10:50:13 -08:00
}
componentDidMount() {
const { dispatch } = this.props;
dispatch(fetchModerationLog())
2021-03-15 15:29:48 -07:00
.then(data => this.setState({
isLoading: false,
lastPage: 1,
}))
2021-01-01 10:50:13 -08:00
.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(() => {});
}
2021-01-01 10:50:13 -08:00
render() {
const { intl, items, hasMore } = this.props;
2021-03-15 15:29:48 -07:00
const { isLoading } = this.state;
2021-01-01 10:50:13 -08:00
const showLoading = isLoading && items.count() === 0;
return (
<Column icon='balance-scale' heading={intl.formatMessage(messages.heading)} backBtnSlim>
2021-01-01 10:50:13 -08:00
<ScrollableList
isLoading={isLoading}
showLoading={showLoading}
scrollKey='moderation-log'
emptyMessage={intl.formatMessage(messages.emptyMessage)}
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
2021-01-01 10:50:13 -08:00
>
{items.map((item, i) => (
<div className='logentry' key={i}>
2021-03-15 16:17:00 -07:00
<div className='logentry__message'>{item.get('message')}</div>
<div className='logentry__timestamp'>
<FormattedDate
value={new Date(item.get('time') * 1000)}
hour12={false}
year='numeric'
month='short'
day='2-digit'
hour='2-digit'
minute='2-digit'
/>
</div>
2021-01-01 10:50:13 -08:00
</div>
))}
</ScrollableList>
</Column>
);
}
}