1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
import {AppBskyLabelerDefs, ComAtprotoModerationDefs} from '@atproto/api'
import {ReportOption} from './utils/useReportOptions'
export type ReportState = {
selectedOption?: ReportOption
selectedLabeler?: AppBskyLabelerDefs.LabelerViewDetailed
details?: string
detailsOpen: boolean
activeStepIndex1: number
error?: string
}
export type ReportAction =
| {
type: 'selectOption'
option: ReportOption
}
| {
type: 'clearOption'
}
| {
type: 'selectLabeler'
labeler: AppBskyLabelerDefs.LabelerViewDetailed
}
| {
type: 'clearLabeler'
}
| {
type: 'setDetails'
details: string
}
| {
type: 'setError'
error: string
}
| {
type: 'clearError'
}
| {
type: 'showDetails'
}
export const initialState: ReportState = {
selectedOption: undefined,
selectedLabeler: undefined,
details: undefined,
detailsOpen: false,
activeStepIndex1: 1,
}
export function reducer(state: ReportState, action: ReportAction): ReportState {
switch (action.type) {
case 'selectOption':
return {
...state,
selectedOption: action.option,
activeStepIndex1: 2,
detailsOpen:
!!state.details ||
action.option.reason === ComAtprotoModerationDefs.REASONOTHER,
}
case 'clearOption':
return {
...state,
selectedOption: undefined,
selectedLabeler: undefined,
activeStepIndex1: 1,
detailsOpen:
!!state.details ||
state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER,
}
case 'selectLabeler':
return {
...state,
selectedLabeler: action.labeler,
activeStepIndex1: 3,
}
case 'clearLabeler':
return {
...state,
selectedLabeler: undefined,
activeStepIndex1: 2,
detailsOpen:
!!state.details ||
state.selectedOption?.reason === ComAtprotoModerationDefs.REASONOTHER,
}
case 'setDetails':
return {
...state,
details: action.details,
}
case 'setError':
return {
...state,
error: action.error,
}
case 'clearError':
return {
...state,
error: undefined,
}
case 'showDetails':
return {
...state,
detailsOpen: true,
}
}
}
|