From b8fb318c0670d5834539ecd2221696bfe87f6f32 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 2 May 2022 14:36:18 -0500 Subject: [PATCH 1/4] ReportModal: fix report forwarding --- .../components/modals/report-modal/steps/other-actions-step.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/features/ui/components/modals/report-modal/steps/other-actions-step.tsx b/app/soapbox/features/ui/components/modals/report-modal/steps/other-actions-step.tsx index b1439807c..1724c6a97 100644 --- a/app/soapbox/features/ui/components/modals/report-modal/steps/other-actions-step.tsx +++ b/app/soapbox/features/ui/components/modals/report-modal/steps/other-actions-step.tsx @@ -32,7 +32,7 @@ const OtherActionsStep = ({ account }: IOtherActionsStep) => { const statusIds = useAppSelector((state) => OrderedSet(state.timelines.getIn([`account:${account.id}:with_replies`, 'items'])).union(state.reports.getIn(['new', 'status_ids']) as Iterable) as OrderedSet); const isBlocked = useAppSelector((state) => state.reports.getIn(['new', 'block']) as boolean); - const isForward = useAppSelector((state) => state.reports.getIn(['reports', 'forward']) as boolean); + const isForward = useAppSelector((state) => state.reports.getIn(['new', 'forward']) as boolean); const canForward = isRemote(account as any) && features.federating; const isSubmitting = useAppSelector((state) => state.reports.getIn(['new', 'isSubmitting']) as boolean); From 9cbe98f131659717a7f31fe49113486e3d6a59e5 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 2 May 2022 14:39:08 -0500 Subject: [PATCH 2/4] Reports: submit rule_ids to API --- app/soapbox/actions/reports.js | 1 + app/soapbox/reducers/reports.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/soapbox/actions/reports.js b/app/soapbox/actions/reports.js index 9a23b51f4..69f9006de 100644 --- a/app/soapbox/actions/reports.js +++ b/app/soapbox/actions/reports.js @@ -60,6 +60,7 @@ export function submitReport() { return api(getState).post('/api/v1/reports', { account_id: getState().getIn(['reports', 'new', 'account_id']), status_ids: getState().getIn(['reports', 'new', 'status_ids']), + rule_ids: getState().getIn(['reports', 'new', 'rule_ids']), comment: getState().getIn(['reports', 'new', 'comment']), forward: getState().getIn(['reports', 'new', 'forward']), }); diff --git a/app/soapbox/reducers/reports.js b/app/soapbox/reducers/reports.js index 74ba75dd2..4103e4bf5 100644 --- a/app/soapbox/reducers/reports.js +++ b/app/soapbox/reducers/reports.js @@ -21,7 +21,7 @@ const initialState = ImmutableMap({ comment: '', forward: false, block: false, - rule_id: null, + rule_ids: ImmutableSet(), }), }); @@ -54,7 +54,7 @@ export default function reports(state = initialState, action) { case REPORT_BLOCK_CHANGE: return state.setIn(['new', 'block'], action.block); case REPORT_RULE_CHANGE: - return state.setIn(['new', 'rule_id'], action.rule_id); + return state.setIn(['new', 'rule_ids'], ImmutableSet([action.rule_id])); case REPORT_SUBMIT_REQUEST: return state.setIn(['new', 'isSubmitting'], true); case REPORT_SUBMIT_FAIL: @@ -66,7 +66,7 @@ export default function reports(state = initialState, action) { map.setIn(['new', 'status_ids'], ImmutableSet()); map.setIn(['new', 'comment'], ''); map.setIn(['new', 'isSubmitting'], false); - map.setIn(['new', 'rule_id'], null); + map.setIn(['new', 'rule_ids'], ImmutableSet()); map.setIn(['new', 'block'], false); }); default: From 83a0988daad0e2bc95b158691792386c2a63ee6a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 2 May 2022 14:40:34 -0500 Subject: [PATCH 3/4] submitReport(): don't call getState() a million times --- app/soapbox/actions/reports.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/soapbox/actions/reports.js b/app/soapbox/actions/reports.js index 69f9006de..8e8e45595 100644 --- a/app/soapbox/actions/reports.js +++ b/app/soapbox/actions/reports.js @@ -56,13 +56,14 @@ export function toggleStatusReport(statusId, checked) { export function submitReport() { return (dispatch, getState) => { dispatch(submitReportRequest()); + const { reports } = getState(); return api(getState).post('/api/v1/reports', { - account_id: getState().getIn(['reports', 'new', 'account_id']), - status_ids: getState().getIn(['reports', 'new', 'status_ids']), - rule_ids: getState().getIn(['reports', 'new', 'rule_ids']), - comment: getState().getIn(['reports', 'new', 'comment']), - forward: getState().getIn(['reports', 'new', 'forward']), + account_id: reports.getIn(['new', 'account_id']), + status_ids: reports.getIn(['new', 'status_ids']), + rule_ids: reports.getIn(['new', 'rule_ids']), + comment: reports.getIn(['new', 'comment']), + forward: reports.getIn(['new', 'forward']), }); }; } From 86ecda84c5b12556535bfd063875229d5870e06f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 2 May 2022 14:47:58 -0500 Subject: [PATCH 4/4] rule_id --> rule_ids --- .../modals/report-modal/__tests__/report-modal.test.tsx | 1 + .../ui/components/modals/report-modal/report-modal.tsx | 6 +++--- .../ui/components/modals/report-modal/steps/reason-step.tsx | 5 +++-- app/soapbox/reducers/__tests__/reports-test.js | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx b/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx index f50732146..28c36e58f 100644 --- a/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx +++ b/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx @@ -28,6 +28,7 @@ describe('', () => { new: { account_id: '1', status_ids: ImmutableSet(['1']), + rule_ids: ImmutableSet(), }, }), statuses: ImmutableMap({ diff --git a/app/soapbox/features/ui/components/modals/report-modal/report-modal.tsx b/app/soapbox/features/ui/components/modals/report-modal/report-modal.tsx index f2891c07d..5845afbb8 100644 --- a/app/soapbox/features/ui/components/modals/report-modal/report-modal.tsx +++ b/app/soapbox/features/ui/components/modals/report-modal/report-modal.tsx @@ -84,7 +84,7 @@ const ReportModal = ({ onClose }: IReportModal) => { const isBlocked = useAppSelector((state) => state.reports.getIn(['new', 'block']) as boolean); const isSubmitting = useAppSelector((state) => state.reports.getIn(['new', 'isSubmitting']) as boolean); const rules = useAppSelector((state) => state.rules.items); - const ruleId = useAppSelector((state) => state.reports.getIn(['new', 'rule_id']) as string); + const ruleIds = useAppSelector((state) => state.reports.getIn(['new', 'rule_ids']) as ImmutableSet); const selectedStatusIds = useAppSelector((state) => state.reports.getIn(['new', 'status_ids']) as ImmutableSet); const shouldRequireRule = rules.length > 0; @@ -152,8 +152,8 @@ const ReportModal = ({ onClose }: IReportModal) => { return false; } - return isSubmitting || (shouldRequireRule && !ruleId) || selectedStatusIds.size === 0; - }, [currentStep, isSubmitting, shouldRequireRule, ruleId, selectedStatusIds.size]); + return isSubmitting || (shouldRequireRule && ruleIds.isEmpty()) || selectedStatusIds.size === 0; + }, [currentStep, isSubmitting, shouldRequireRule, ruleIds, selectedStatusIds.size]); const calculateProgress = useCallback(() => { switch (currentStep) { diff --git a/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx b/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx index fa0ba4325..1badbe94f 100644 --- a/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx +++ b/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx @@ -8,6 +8,7 @@ import { fetchRules } from 'soapbox/actions/rules'; import { FormGroup, Stack, Text, Textarea } from 'soapbox/components/ui'; import { useAppSelector } from 'soapbox/hooks'; +import type { Set as ImmutableSet } from 'immutable'; import type { ReducerAccount } from 'soapbox/reducers/accounts'; const messages = defineMessages({ @@ -32,7 +33,7 @@ const ReasonStep = (_props: IReasonStep) => { const comment = useAppSelector((state) => state.reports.getIn(['new', 'comment']) as string); const rules = useAppSelector((state) => state.rules.items); - const ruleId = useAppSelector((state) => state.reports.getIn(['new', 'rule_id']) as boolean); + const ruleIds = useAppSelector((state) => state.reports.getIn(['new', 'rule_ids']) as ImmutableSet); const shouldRequireRule = rules.length > 0; const handleCommentChange = (event: React.ChangeEvent) => { @@ -87,7 +88,7 @@ const ReasonStep = (_props: IReasonStep) => { ref={rulesListRef} > {rules.map((rule, idx) => { - const isSelected = String(ruleId) === String(rule.id); + const isSelected = ruleIds.includes(String(rule.id)); return (