Implement report submission
This commit is contained in:
@@ -21,6 +21,7 @@ import {Loader} from '#/components/Loader'
|
|||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
|
|
||||||
import {ReportDialogProps} from './types'
|
import {ReportDialogProps} from './types'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export function SubmitView({
|
export function SubmitView({
|
||||||
params,
|
params,
|
||||||
@@ -41,10 +42,11 @@ export function SubmitView({
|
|||||||
const [selectedServices, setSelectedServices] = React.useState<string[]>(
|
const [selectedServices, setSelectedServices] = React.useState<string[]>(
|
||||||
labelers?.map(labeler => labeler.creator.did) || [],
|
labelers?.map(labeler => labeler.creator.did) || [],
|
||||||
)
|
)
|
||||||
|
const [error, setError] = React.useState('')
|
||||||
|
|
||||||
const submit = React.useCallback(async () => {
|
const submit = React.useCallback(async () => {
|
||||||
setSubmitting(true)
|
setSubmitting(true)
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
setError('')
|
||||||
|
|
||||||
const $type =
|
const $type =
|
||||||
params.type === 'account'
|
params.type === 'account'
|
||||||
@@ -58,15 +60,39 @@ export function SubmitView({
|
|||||||
},
|
},
|
||||||
reason: details,
|
reason: details,
|
||||||
}
|
}
|
||||||
console.log(report)
|
const results = await Promise.all(
|
||||||
// await getAgent().createModerationReport(report)
|
selectedServices.map(did =>
|
||||||
|
getAgent()
|
||||||
|
.withProxy('atproto_labeler', did)
|
||||||
|
.createModerationReport(report)
|
||||||
|
.then(
|
||||||
|
_ => true,
|
||||||
|
_ => false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
|
|
||||||
Toast.show(`Thank you. Your report has been sent.`)
|
if (results.includes(true)) {
|
||||||
|
Toast.show(_(msg`Thank you. Your report has been sent.`))
|
||||||
onSubmitComplete()
|
onSubmitComplete()
|
||||||
}, [params, details, selectedReportOption, onSubmitComplete])
|
} else {
|
||||||
|
setError(
|
||||||
|
_(
|
||||||
|
msg`There was an issue sending your report. Please check your internet connection.`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
_,
|
||||||
|
params,
|
||||||
|
details,
|
||||||
|
selectedReportOption,
|
||||||
|
selectedServices,
|
||||||
|
onSubmitComplete,
|
||||||
|
setError,
|
||||||
|
])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[a.gap_2xl]}>
|
<View style={[a.gap_2xl]}>
|
||||||
@@ -163,7 +189,8 @@ export function SubmitView({
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={[a.flex_row, a.align_center, a.justify_end, a.gap_lg]}>
|
<View style={[a.flex_row, a.align_center, a.justify_end, a.gap_lg]}>
|
||||||
{!selectedServices.length && (
|
{!selectedServices.length ||
|
||||||
|
(error && (
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
a.flex_1,
|
a.flex_1,
|
||||||
@@ -171,9 +198,13 @@ export function SubmitView({
|
|||||||
a.leading_snug,
|
a.leading_snug,
|
||||||
t.atoms.text_contrast_medium,
|
t.atoms.text_contrast_medium,
|
||||||
]}>
|
]}>
|
||||||
|
{error ? (
|
||||||
|
error
|
||||||
|
) : (
|
||||||
<Trans>You must select at least one labeler for a report</Trans>
|
<Trans>You must select at least one labeler for a report</Trans>
|
||||||
</Text>
|
|
||||||
)}
|
)}
|
||||||
|
</Text>
|
||||||
|
))}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="large"
|
size="large"
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ let ProfileHeaderLabeler = ({
|
|||||||
preferences?.moderationPrefs.labelers.find(l => l.did === profile.did)
|
preferences?.moderationPrefs.labelers.find(l => l.did === profile.did)
|
||||||
const canSubscribe =
|
const canSubscribe =
|
||||||
isSubscribed ||
|
isSubscribed ||
|
||||||
(preferences ? preferences?.moderationPrefs.labelers.length < 10 : false)
|
(preferences ? preferences?.moderationPrefs.labelers.length < 9 : false)
|
||||||
const {mutateAsync: likeMod, isPending: isLikePending} = useLikeMutation()
|
const {mutateAsync: likeMod, isPending: isLikePending} = useLikeMutation()
|
||||||
const {mutateAsync: unlikeMod, isPending: isUnlikePending} =
|
const {mutateAsync: unlikeMod, isPending: isUnlikePending} =
|
||||||
useUnlikeMutation()
|
useUnlikeMutation()
|
||||||
|
|||||||
Reference in New Issue
Block a user