Reports: import statuses, add getReport selector
This commit is contained in:
parent
90414939a5
commit
a8893907d4
4 changed files with 22 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
import api from '../api';
|
||||
import { importFetchedStatuses } from 'soapbox/actions/importer';
|
||||
|
||||
export const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST';
|
||||
export const ADMIN_CONFIG_FETCH_SUCCESS = 'ADMIN_CONFIG_FETCH_SUCCESS';
|
||||
|
@ -64,6 +65,7 @@ export function fetchReports(params) {
|
|||
return api(getState)
|
||||
.get('/api/pleroma/admin/reports', { params })
|
||||
.then(({ data: { reports } }) => {
|
||||
reports.forEach(report => dispatch(importFetchedStatuses(report.statuses)));
|
||||
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
||||
|
|
|
@ -8,6 +8,7 @@ import Column from '../ui/components/column';
|
|||
import ScrollableList from 'soapbox/components/scrollable_list';
|
||||
import { fetchReports } from 'soapbox/actions/admin';
|
||||
import Report from './components/report';
|
||||
import { makeGetReport } from 'soapbox/selectors';
|
||||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'column.admin.reports', defaultMessage: 'Reports' },
|
||||
|
@ -15,9 +16,11 @@ const messages = defineMessages({
|
|||
});
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const getReport = makeGetReport();
|
||||
const ids = state.getIn(['admin', 'openReports']);
|
||||
|
||||
return {
|
||||
reports: ids.toList().map(id => state.getIn(['admin', 'reports', id])),
|
||||
reports: ids.map(id => getReport(state, id)),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ function approveUsers(state, users) {
|
|||
function importReports(state, reports) {
|
||||
return state.withMutations(state => {
|
||||
reports.forEach(report => {
|
||||
report.statuses = report.statuses.map(status => status.id);
|
||||
if (report.state === 'open') {
|
||||
state.update('openReports', orderedSet => orderedSet.add(report.id));
|
||||
}
|
||||
|
|
|
@ -175,3 +175,18 @@ export const makeGetChat = () => {
|
|||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const makeGetReport = () => {
|
||||
return createSelector(
|
||||
[
|
||||
(state, id) => state.getIn(['admin', 'reports', id]),
|
||||
(state, id) => state.getIn(['admin', 'reports', id, 'statuses']).map(
|
||||
statusId => state.getIn(['statuses', statusId])),
|
||||
],
|
||||
|
||||
(report, statuses) => {
|
||||
if (!report) return null;
|
||||
return report.set('statuses', statuses);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue