2022-01-10 14:17:52 -08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-12-31 12:41:43 -08:00
|
|
|
import React from 'react';
|
2022-01-10 14:17:52 -08:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2020-12-31 12:41:43 -08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { connect } from 'react-redux';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-12-31 12:41:43 -08:00
|
|
|
import { fetchReports } from 'soapbox/actions/admin';
|
2022-01-10 14:17:52 -08:00
|
|
|
import ScrollableList from 'soapbox/components/scrollable_list';
|
2020-12-31 18:11:08 -08:00
|
|
|
import { makeGetReport } from 'soapbox/selectors';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import Column from '../ui/components/better_column';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import Report from './components/report';
|
2020-12-31 12:41:43 -08:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
heading: { id: 'column.admin.reports', defaultMessage: 'Reports' },
|
2021-01-01 12:06:12 -08:00
|
|
|
modlog: { id: 'column.admin.reports.menu.moderation_log', defaultMessage: 'Moderation Log' },
|
2020-12-31 16:31:50 -08:00
|
|
|
emptyMessage: { id: 'admin.reports.empty_message', defaultMessage: 'There are no open reports. If a user gets reported, they will show up here.' },
|
2020-12-31 12:41:43 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
2020-12-31 18:11:08 -08:00
|
|
|
const getReport = makeGetReport();
|
2020-12-31 12:41:43 -08:00
|
|
|
const ids = state.getIn(['admin', 'openReports']);
|
2020-12-31 18:11:08 -08:00
|
|
|
|
2020-12-31 12:41:43 -08:00
|
|
|
return {
|
2020-12-31 21:16:50 -08:00
|
|
|
reports: ids.toList().map(id => getReport(state, id)),
|
2020-12-31 12:41:43 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Reports extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
reports: ImmutablePropTypes.list.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
isLoading: true,
|
|
|
|
}
|
|
|
|
|
2021-01-01 12:06:12 -08:00
|
|
|
makeColumnMenu = () => {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return [{
|
|
|
|
text: intl.formatMessage(messages.modlog),
|
|
|
|
to: '/admin/log',
|
2021-11-04 12:19:04 -07:00
|
|
|
icon: require('@tabler/icons/icons/list.svg'),
|
2021-01-01 12:06:12 -08:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2020-12-31 12:41:43 -08:00
|
|
|
componentDidMount() {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(fetchReports())
|
|
|
|
.then(() => this.setState({ isLoading: false }))
|
|
|
|
.catch(() => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { intl, reports } = this.props;
|
|
|
|
const { isLoading } = this.state;
|
|
|
|
const showLoading = isLoading && reports.count() === 0;
|
|
|
|
|
|
|
|
return (
|
2022-03-29 07:26:02 -07:00
|
|
|
<Column icon='gavel' label={intl.formatMessage(messages.heading)} menu={this.makeColumnMenu()}>
|
2020-12-31 15:20:46 -08:00
|
|
|
<ScrollableList
|
|
|
|
isLoading={isLoading}
|
|
|
|
showLoading={showLoading}
|
|
|
|
scrollKey='admin-reports'
|
|
|
|
emptyMessage={intl.formatMessage(messages.emptyMessage)}
|
|
|
|
>
|
2020-12-31 21:16:50 -08:00
|
|
|
{reports.map(report => <Report report={report} key={report.get('id')} />)}
|
2020-12-31 12:41:43 -08:00
|
|
|
</ScrollableList>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|