diff --git a/app/soapbox/actions/admin.js b/app/soapbox/actions/admin.js index ecf70923a..a6b38f962 100644 --- a/app/soapbox/actions/admin.js +++ b/app/soapbox/actions/admin.js @@ -55,8 +55,8 @@ export function fetchReports(params) { dispatch({ type: ADMIN_REPORTS_FETCH_REQUEST, params }); return api(getState) .get('/api/pleroma/admin/reports', { params }) - .then(({ data }) => { - dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, data, params }); + .then(({ data: { reports } }) => { + dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params }); }).catch(error => { dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params }); }); diff --git a/app/soapbox/components/helmet.js b/app/soapbox/components/helmet.js index 080f234c1..d89b36aae 100644 --- a/app/soapbox/components/helmet.js +++ b/app/soapbox/components/helmet.js @@ -6,7 +6,7 @@ import { Helmet } from'react-helmet'; const getNotifTotals = state => { const notifications = state.getIn(['notifications', 'unread'], 0); const chats = state.get('chats').reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0); - const reports = state.getIn(['admin', 'open_report_count'], 0); + const reports = state.getIn(['admin', 'openReports']).count(); const approvals = state.getIn(['admin', 'awaitingApproval']).count(); return notifications + chats + reports + approvals; }; diff --git a/app/soapbox/features/admin/components/admin_nav.js b/app/soapbox/features/admin/components/admin_nav.js index 1d0a9a47f..6f5e69c95 100644 --- a/app/soapbox/features/admin/components/admin_nav.js +++ b/app/soapbox/features/admin/components/admin_nav.js @@ -10,7 +10,7 @@ import { FormattedMessage } from 'react-intl'; const mapStateToProps = (state, props) => ({ instance: state.get('instance'), approvalCount: state.getIn(['admin', 'awaitingApproval']).count(), - reportsCount: state.getIn(['admin', 'open_report_count']), + reportsCount: state.getIn(['admin', 'openReports']).count(), }); export default @connect(mapStateToProps) diff --git a/app/soapbox/features/admin/components/registration_mode_picker.js b/app/soapbox/features/admin/components/registration_mode_picker.js index dd007dba4..1e2f153ae 100644 --- a/app/soapbox/features/admin/components/registration_mode_picker.js +++ b/app/soapbox/features/admin/components/registration_mode_picker.js @@ -17,7 +17,6 @@ const messages = defineMessages({ const mapStateToProps = (state, props) => ({ mode: modeFromInstance(state.get('instance')), - openReportCount: state.getIn(['admin', 'open_report_count']), }); const generateConfig = mode => { diff --git a/app/soapbox/features/ui/components/tabs_bar.js b/app/soapbox/features/ui/components/tabs_bar.js index 013eef313..fa4a685f4 100644 --- a/app/soapbox/features/ui/components/tabs_bar.js +++ b/app/soapbox/features/ui/components/tabs_bar.js @@ -154,7 +154,7 @@ class TabsBar extends React.PureComponent { const mapStateToProps = state => { const me = state.get('me'); - const reportsCount = state.getIn(['admin', 'open_report_count']); + const reportsCount = state.getIn(['admin', 'openReports']).count(); const approvalCount = state.getIn(['admin', 'awaitingApproval']).count(); return { account: state.getIn(['accounts', me]), diff --git a/app/soapbox/reducers/__tests__/admin-test.js b/app/soapbox/reducers/__tests__/admin-test.js index 9f983af0a..4f9ce0aa9 100644 --- a/app/soapbox/reducers/__tests__/admin-test.js +++ b/app/soapbox/reducers/__tests__/admin-test.js @@ -3,18 +3,17 @@ import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, - fromJS, } from 'immutable'; describe('admin reducer', () => { it('should return the initial state', () => { - expect(reducer(undefined, {})).toEqual(fromJS({ - reports: [], - open_report_count: 0, + expect(reducer(undefined, {})).toEqual({ + reports: ImmutableMap(), + openReports: ImmutableOrderedSet(), users: ImmutableMap(), awaitingApproval: ImmutableOrderedSet(), configs: ImmutableList(), needsReboot: false, - })); + }); }); }); diff --git a/app/soapbox/reducers/admin.js b/app/soapbox/reducers/admin.js index eaacf7323..bdcdcd9ec 100644 --- a/app/soapbox/reducers/admin.js +++ b/app/soapbox/reducers/admin.js @@ -15,9 +15,9 @@ import { } from 'immutable'; const initialState = ImmutableMap({ - reports: ImmutableList(), + reports: ImmutableMap(), + openReports: ImmutableOrderedSet(), users: ImmutableMap(), - open_report_count: 0, awaitingApproval: ImmutableOrderedSet(), configs: ImmutableList(), needsReboot: false, @@ -52,18 +52,23 @@ function approveUsers(state, users) { }); } +function importReports(state, reports) { + return state.withMutations(state => { + reports.forEach(report => { + if (report.state === 'open') { + state.update('openReports', orderedSet => orderedSet.add(report.id)); + } + state.setIn(['reports', report.id], fromJS(report)); + }); + }); +} + export default function admin(state = initialState, action) { switch(action.type) { case ADMIN_CONFIG_FETCH_SUCCESS: return state.set('configs', fromJS(action.configs)); case ADMIN_REPORTS_FETCH_SUCCESS: - if (action.params && action.params.state === 'open') { - return state - .set('reports', fromJS(action.data.reports)) - .set('open_report_count', action.data.total); - } else { - return state.set('reports', fromJS(action.data.reports)); - } + return importReports(state, action.reports); case ADMIN_USERS_FETCH_SUCCESS: return importUsers(state, action.data.users); case ADMIN_USERS_DELETE_REQUEST: