From 020feec15b754f5bcd2bd57d78f2362f73bcb22d Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 24 Sep 2025 21:47:19 -0700 Subject: [PATCH] cleanup open/closed logic --- .../moderation/ReportDialog/index.tsx | 6 ++++- .../moderation/ReportDialog/state.ts | 25 ++++++++----------- .../ReportDialog/utils/useReportOptions.ts | 11 ++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/components/moderation/ReportDialog/index.tsx b/src/components/moderation/ReportDialog/index.tsx index a4e06e72ee..9382b9701f 100644 --- a/src/components/moderation/ReportDialog/index.tsx +++ b/src/components/moderation/ReportDialog/index.tsx @@ -266,7 +266,11 @@ function Inner(props: ReportDialogProps) { key={o.key} option={o} onSelect={() => { - dispatch({type: 'selectCategory', option: o}) + dispatch({ + type: 'selectCategory', + option: o, + otherOption: getCategory('other').options[0], + }) }} /> ))} diff --git a/src/components/moderation/ReportDialog/state.ts b/src/components/moderation/ReportDialog/state.ts index 19d107cf3a..97d4744e79 100644 --- a/src/components/moderation/ReportDialog/state.ts +++ b/src/components/moderation/ReportDialog/state.ts @@ -1,6 +1,7 @@ -import {type AppBskyLabelerDefs, ComAtprotoModerationDefs} from '@atproto/api' +import {type AppBskyLabelerDefs} from '@atproto/api' import { + OtherReportReasons, type ReportOption, type ReportOptionCategory, } from './utils/useReportOptions' @@ -19,6 +20,7 @@ export type ReportAction = | { type: 'selectCategory' option: ReportOptionCategory + otherOption: ReportOption } | { type: 'clearCategory' @@ -67,8 +69,10 @@ export function reducer(state: ReportState, action: ReportAction): ReportState { return { ...state, selectedCategory: action.option, - activeStepIndex1: 2, - detailsOpen: !!state.details, + activeStepIndex1: action.option.key === 'other' ? 3 : 2, + selectedOption: + action.option.key === 'other' ? action.otherOption : undefined, + detailsOpen: state.selectedCategory?.key === 'other', } case 'clearCategory': return { @@ -77,18 +81,14 @@ export function reducer(state: ReportState, action: ReportAction): ReportState { selectedOption: undefined, selectedLabeler: undefined, activeStepIndex1: 1, - detailsOpen: - !!state.details || - state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER, + detailsOpen: false, } case 'selectOption': return { ...state, selectedOption: action.option, activeStepIndex1: 3, - detailsOpen: - !!state.details || - action.option.reason === ComAtprotoModerationDefs.REASONOTHER, + detailsOpen: OtherReportReasons.has(action.option.reason), } case 'clearOption': return { @@ -96,9 +96,7 @@ export function reducer(state: ReportState, action: ReportAction): ReportState { selectedOption: undefined, selectedLabeler: undefined, activeStepIndex1: 2, - detailsOpen: - !!state.details || - state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER, + detailsOpen: false, } case 'selectLabeler': return { @@ -111,9 +109,6 @@ export function reducer(state: ReportState, action: ReportAction): ReportState { ...state, selectedLabeler: undefined, activeStepIndex1: 3, - detailsOpen: - !!state.details || - state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER, } case 'setDetails': return { diff --git a/src/components/moderation/ReportDialog/utils/useReportOptions.ts b/src/components/moderation/ReportDialog/utils/useReportOptions.ts index e25296f350..1ab05a8b0c 100644 --- a/src/components/moderation/ReportDialog/utils/useReportOptions.ts +++ b/src/components/moderation/ReportDialog/utils/useReportOptions.ts @@ -37,6 +37,17 @@ export interface ReportOption { reason: ReasonType } +export const OtherReportReasons = new Set([ + 'com.atproto.moderation.defs#reasonOther', + 'tools.ozone.report.defs#reasonChildSafetyOther', + 'tools.ozone.report.defs#reasonViolenceOther', + 'tools.ozone.report.defs#reasonSexualOther', + 'tools.ozone.report.defs#reasonHarassmentOther', + 'tools.ozone.report.defs#reasonMisleadingOther', + 'tools.ozone.report.defs#reasonRuleOther', + 'tools.ozone.report.defs#reasonChildSafetyOther', +]) + export function useReportOptions() { const {_} = useLingui()