Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215import {OTHER_REPORT_REASONS} from '#/components/moderation/ReportDialog/const'import { type ReportCategoryConfig, type ReportOption,} from '#/components/moderation/ReportDialog/utils/useReportOptions'import {type app, tools} from '#/lexicons'
export type NciiQualification = { isDepicted?: boolean}
export type ReportState = { selectedCategory?: ReportCategoryConfig selectedOption?: ReportOption selectedLabeler?: app.bsky.labeler.defs.LabelerViewDetailed details?: string detailsOpen: boolean activeStepIndex1: number error?: string /** * Whether to attach how far the viewer had watched to the report. Only * offered for posts with a video. */ includeVideoTimestamp: boolean /** * Present while the selected reason is NCII. Tracks the answer to the * qualifying question that determines whether the report should go through * the external NCII report form instead of in-app submission. */ ncii?: NciiQualification}
/** * Resolves the NCII qualifying question into an outcome. The depicted person * (or their authorized representative) is directed to the external NCII * report form; everyone else proceeds with the normal in-app submission. */export function getNciiQualificationOutcome( ncii?: NciiQualification,): 'pending' | 'externalForm' | 'inApp' | undefined { if (!ncii) return undefined if (ncii.isDepicted === true) return 'externalForm' if (ncii.isDepicted === false) return 'inApp' return 'pending'}
export type ReportAction = | { type: 'selectCategory' option: ReportCategoryConfig otherOption: ReportOption } | { type: 'clearCategory' } | { type: 'selectOption' option: ReportOption } | { type: 'clearOption' } | { type: 'answerNciiQuestion' question: keyof NciiQualification answer: boolean } | { type: 'selectLabeler' labeler: app.bsky.labeler.defs.LabelerViewDetailed } | { type: 'clearLabeler' } | { type: 'setDetails' details: string } | { type: 'setError' error: string } | { type: 'clearError' } | { type: 'showDetails' } | { type: 'setIncludeVideoTimestamp' include: boolean }
export const initialState: ReportState = { selectedCategory: undefined, selectedOption: undefined, selectedLabeler: undefined, details: undefined, detailsOpen: false, activeStepIndex1: 1, includeVideoTimestamp: false,}
export function reducer(state: ReportState, action: ReportAction): ReportState { switch (action.type) { case 'selectCategory': return { ...state, selectedCategory: action.option, activeStepIndex1: action.option.key === 'other' ? 3 : 2, selectedOption: action.option.key === 'other' ? action.otherOption : undefined, } case 'clearCategory': return { ...state, selectedCategory: undefined, selectedOption: undefined, selectedLabeler: undefined, activeStepIndex1: 1, detailsOpen: false, ncii: undefined, includeVideoTimestamp: false, } case 'selectOption': { const isNcii = action.option.reason === tools.ozone.report.defs.reasonSexualNCII.value return { ...state, selectedOption: action.option, // NCII reports require answering qualifying questions before moving on activeStepIndex1: isNcii ? 2 : 3, detailsOpen: OTHER_REPORT_REASONS.has(action.option.reason), ncii: isNcii ? {} : undefined, } } case 'clearOption': return { ...state, selectedOption: undefined, selectedLabeler: undefined, activeStepIndex1: 2, detailsOpen: false, ncii: undefined, includeVideoTimestamp: false, } case 'answerNciiQuestion': { const ncii = {...state.ncii, [action.question]: action.answer} return { ...state, ncii, activeStepIndex1: getNciiQualificationOutcome(ncii) === 'inApp' ? state.selectedLabeler ? 4 : 3 : 2, } } case 'selectLabeler': return { ...state, selectedLabeler: action.labeler, /* * Labelers may be auto-selected (e.g. chat reports only go to * Bluesky), so don't advance past pending NCII qualifying questions. */ activeStepIndex1: getNciiQualificationOutcome(state.ncii) === 'inApp' || !state.ncii ? 4 : 2, detailsOpen: state.selectedOption ? OTHER_REPORT_REASONS.has(state.selectedOption?.reason) : false, /* * Picking a service is a fresh consent decision - the opt-in is scoped * to Bluesky, so it must not survive a switch to another labeler. */ includeVideoTimestamp: false, } case 'clearLabeler': return { ...state, selectedLabeler: undefined, activeStepIndex1: 3, includeVideoTimestamp: false, } 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, } case 'setIncludeVideoTimestamp': return { ...state, includeVideoTimestamp: action.include, } }}