Bluesky app fork with some witchin' additions 馃挮
at readme-update 136 lines 3.1 kB view raw
1import {type AppBskyLabelerDefs} from '@atproto/api' 2 3import {OTHER_REPORT_REASONS} from '#/components/moderation/ReportDialog/const' 4import { 5 type ReportCategoryConfig, 6 type ReportOption, 7} from '#/components/moderation/ReportDialog/utils/useReportOptions' 8 9export type ReportState = { 10 selectedCategory?: ReportCategoryConfig 11 selectedOption?: ReportOption 12 selectedLabeler?: AppBskyLabelerDefs.LabelerViewDetailed 13 details?: string 14 detailsOpen: boolean 15 activeStepIndex1: number 16 error?: string 17} 18 19export type ReportAction = 20 | { 21 type: 'selectCategory' 22 option: ReportCategoryConfig 23 otherOption: ReportOption 24 } 25 | { 26 type: 'clearCategory' 27 } 28 | { 29 type: 'selectOption' 30 option: ReportOption 31 } 32 | { 33 type: 'clearOption' 34 } 35 | { 36 type: 'selectLabeler' 37 labeler: AppBskyLabelerDefs.LabelerViewDetailed 38 } 39 | { 40 type: 'clearLabeler' 41 } 42 | { 43 type: 'setDetails' 44 details: string 45 } 46 | { 47 type: 'setError' 48 error: string 49 } 50 | { 51 type: 'clearError' 52 } 53 | { 54 type: 'showDetails' 55 } 56 57export const initialState: ReportState = { 58 selectedCategory: undefined, 59 selectedOption: undefined, 60 selectedLabeler: undefined, 61 details: undefined, 62 detailsOpen: false, 63 activeStepIndex1: 1, 64} 65 66export function reducer(state: ReportState, action: ReportAction): ReportState { 67 switch (action.type) { 68 case 'selectCategory': 69 return { 70 ...state, 71 selectedCategory: action.option, 72 activeStepIndex1: action.option.key === 'other' ? 3 : 2, 73 selectedOption: 74 action.option.key === 'other' ? action.otherOption : undefined, 75 } 76 case 'clearCategory': 77 return { 78 ...state, 79 selectedCategory: undefined, 80 selectedOption: undefined, 81 selectedLabeler: undefined, 82 activeStepIndex1: 1, 83 detailsOpen: false, 84 } 85 case 'selectOption': 86 return { 87 ...state, 88 selectedOption: action.option, 89 activeStepIndex1: 3, 90 detailsOpen: OTHER_REPORT_REASONS.has(action.option.reason), 91 } 92 case 'clearOption': 93 return { 94 ...state, 95 selectedOption: undefined, 96 selectedLabeler: undefined, 97 activeStepIndex1: 2, 98 detailsOpen: false, 99 } 100 case 'selectLabeler': 101 return { 102 ...state, 103 selectedLabeler: action.labeler, 104 activeStepIndex1: 4, 105 detailsOpen: state.selectedOption 106 ? OTHER_REPORT_REASONS.has(state.selectedOption?.reason) 107 : false, 108 } 109 case 'clearLabeler': 110 return { 111 ...state, 112 selectedLabeler: undefined, 113 activeStepIndex1: 3, 114 } 115 case 'setDetails': 116 return { 117 ...state, 118 details: action.details, 119 } 120 case 'setError': 121 return { 122 ...state, 123 error: action.error, 124 } 125 case 'clearError': 126 return { 127 ...state, 128 error: undefined, 129 } 130 case 'showDetails': 131 return { 132 ...state, 133 detailsOpen: true, 134 } 135 } 136}