cleanup open/closed logic
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user