From 36478a3eeac59f42a7d6a2367f9237328800d274 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 12 Mar 2024 12:20:54 -0700 Subject: [PATCH] Implement report submission --- src/components/ReportDialog/SubmitView.tsx | 67 ++++++++++++++----- .../Profile/Header/ProfileHeaderLabeler.tsx | 2 +- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/components/ReportDialog/SubmitView.tsx b/src/components/ReportDialog/SubmitView.tsx index 3d4e29026b..60453eb76e 100644 --- a/src/components/ReportDialog/SubmitView.tsx +++ b/src/components/ReportDialog/SubmitView.tsx @@ -21,6 +21,7 @@ import {Loader} from '#/components/Loader' import * as Toast from '#/view/com/util/Toast' import {ReportDialogProps} from './types' +import {getAgent} from '#/state/session' export function SubmitView({ params, @@ -41,10 +42,11 @@ export function SubmitView({ const [selectedServices, setSelectedServices] = React.useState( labelers?.map(labeler => labeler.creator.did) || [], ) + const [error, setError] = React.useState('') const submit = React.useCallback(async () => { setSubmitting(true) - await new Promise(resolve => setTimeout(resolve, 1000)) + setError('') const $type = params.type === 'account' @@ -58,15 +60,39 @@ export function SubmitView({ }, reason: details, } - console.log(report) - // await getAgent().createModerationReport(report) + const results = await Promise.all( + selectedServices.map(did => + getAgent() + .withProxy('atproto_labeler', did) + .createModerationReport(report) + .then( + _ => true, + _ => false, + ), + ), + ) setSubmitting(false) - Toast.show(`Thank you. Your report has been sent.`) - - onSubmitComplete() - }, [params, details, selectedReportOption, onSubmitComplete]) + 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, + ]) return ( @@ -163,17 +189,22 @@ export function SubmitView({ - {!selectedServices.length && ( - - You must select at least one labeler for a report - - )} + {!selectedServices.length || + (error && ( + + {error ? ( + error + ) : ( + You must select at least one labeler for a report + )} + + ))}