import React from 'react' import {View} from 'react-native' import {AppBskyLabelerDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {getLabelingServiceTitle} from '#/lib/moderation' import {ReportOption} from '#/lib/moderation/useReportOptions' import {useAgent} from '#/state/session' import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' import * as Toast from '#/view/com/util/Toast' import {atoms as a, native, useTheme} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import * as Toggle from '#/components/forms/Toggle' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron' import {Loader} from '#/components/Loader' import {Text} from '#/components/Typography' import {ReportDialogProps} from './types' export function SubmitView({ params, labelers, selectedLabeler, selectedReportOption, goBack, onSubmitComplete, }: ReportDialogProps & { labelers: AppBskyLabelerDefs.LabelerViewDetailed[] selectedLabeler: string selectedReportOption: ReportOption goBack: () => void onSubmitComplete: () => void }) { const t = useTheme() const {_} = useLingui() const agent = useAgent() const [details, setDetails] = React.useState('') const [submitting, setSubmitting] = React.useState(false) const [selectedServices, setSelectedServices] = React.useState([ selectedLabeler, ]) const [error, setError] = React.useState('') const submit = React.useCallback(async () => { setSubmitting(true) setError('') const $type = params.type === 'account' ? 'com.atproto.admin.defs#repoRef' : 'com.atproto.repo.strongRef' const report = { reasonType: selectedReportOption.reason, subject: { $type, ...params, }, reason: details, } const results = await Promise.all( selectedServices.map(did => agent .withProxy('atproto_labeler', did) .createModerationReport(report) .then( _ => true, _ => false, ), ), ) setSubmitting(false) if (results.includes(true)) { Toast.show(_(msg`Thank you. Your report has been sent.`)) onSubmitComplete() } else { setError( _( msg`There was an issue sending your report. Please check your internet connection.`, ), ) } }, [ _, params, details, selectedReportOption, selectedServices, onSubmitComplete, setError, agent, ]) return ( {selectedReportOption.title} {selectedReportOption.description} Select the moderation service(s) to report to {labelers.map(labeler => { const title = getLabelingServiceTitle({ displayName: labeler.creator.displayName, handle: labeler.creator.handle, }) return ( ) })} Optionally provide additional information below: {!selectedServices.length || (error && ( {error ? ( error ) : ( You must select at least one labeler for a report )} ))} ) } function LabelerToggle({title}: {title: string}) { const t = useTheme() const ctx = Toggle.useItemContext() return ( {title} ) }