From fa9421a7c18c35dcfb251d9a5cc35395296d351a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 24 Aug 2020 18:00:09 -0500 Subject: [PATCH] Reports counter: Only count open reports --- app/soapbox/actions/admin.js | 2 +- .../features/ui/components/reports_counter_icon.js | 2 +- app/soapbox/features/ui/index.js | 3 ++- app/soapbox/reducers/__tests__/admin-test.js | 2 +- app/soapbox/reducers/admin.js | 11 ++++++++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/soapbox/actions/admin.js b/app/soapbox/actions/admin.js index 19bc283e0..cf3a5d0e7 100644 --- a/app/soapbox/actions/admin.js +++ b/app/soapbox/actions/admin.js @@ -25,7 +25,7 @@ export function fetchReports(params) { return (dispatch, getState) => { dispatch({ type: ADMIN_REPORTS_FETCH_REQUEST, params }); return api(getState) - .get('/api/pleroma/admin/reports', params) + .get('/api/pleroma/admin/reports', { params }) .then(({ data }) => { dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, data, params }); }).catch(error => { diff --git a/app/soapbox/features/ui/components/reports_counter_icon.js b/app/soapbox/features/ui/components/reports_counter_icon.js index 82d276791..14a121887 100644 --- a/app/soapbox/features/ui/components/reports_counter_icon.js +++ b/app/soapbox/features/ui/components/reports_counter_icon.js @@ -2,7 +2,7 @@ import { connect } from 'react-redux'; import IconWithBadge from 'soapbox/components/icon_with_badge'; const mapStateToProps = state => ({ - count: state.getIn(['admin', 'report_count']), + count: state.getIn(['admin', 'open_report_count']), id: 'gavel', }); diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index 747979247..cdac3a3d8 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -422,7 +422,8 @@ class UI extends React.PureComponent { this.props.dispatch(expandHomeTimeline()); this.props.dispatch(expandNotifications()); // this.props.dispatch(fetchGroups('member')); - if (isStaff(account)) this.props.dispatch(fetchReports()); + if (isStaff(account)) + this.props.dispatch(fetchReports({ state: 'open' })); setTimeout(() => this.props.dispatch(fetchFilters()), 500); } diff --git a/app/soapbox/reducers/__tests__/admin-test.js b/app/soapbox/reducers/__tests__/admin-test.js index e3f0fa370..aa32ace8f 100644 --- a/app/soapbox/reducers/__tests__/admin-test.js +++ b/app/soapbox/reducers/__tests__/admin-test.js @@ -5,7 +5,7 @@ describe('admin reducer', () => { it('should return the initial state', () => { expect(reducer(undefined, {})).toEqual(fromJS({ reports: [], - report_count: 0, + open_report_count: 0, })); }); }); diff --git a/app/soapbox/reducers/admin.js b/app/soapbox/reducers/admin.js index 404d5187b..2a41666f6 100644 --- a/app/soapbox/reducers/admin.js +++ b/app/soapbox/reducers/admin.js @@ -3,14 +3,19 @@ import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; const initialState = ImmutableMap({ reports: ImmutableList(), - report_count: 0, + open_report_count: 0, }); export default function admin(state = initialState, action) { switch(action.type) { case ADMIN_REPORTS_FETCH_SUCCESS: - return state.set('reports', fromJS(action.data.reports)) - .set('report_count', action.data.total); + 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)); + } default: return state; }