cleanup open/closed logic
This commit is contained in:
@@ -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],
|
||||
})
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -37,6 +37,17 @@ export interface ReportOption {
|
||||
reason: ReasonType
|
||||
}
|
||||
|
||||
export const OtherReportReasons = new Set<ReasonType | undefined>([
|
||||
'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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user