From 700693b87b27a111ff175a23185e239b0c4e4c42 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 15 Feb 2024 18:23:58 -0600 Subject: [PATCH] ReportDialog updates --- src/components/dialogs/ReportDialog/index.tsx | 296 ++++++++++-------- 1 file changed, 158 insertions(+), 138 deletions(-) diff --git a/src/components/dialogs/ReportDialog/index.tsx b/src/components/dialogs/ReportDialog/index.tsx index aac84c3992..9736e52d1c 100644 --- a/src/components/dialogs/ReportDialog/index.tsx +++ b/src/components/dialogs/ReportDialog/index.tsx @@ -1,9 +1,8 @@ import React from 'react' -import {View, Dimensions, Linking} from 'react-native' +import {View, Linking} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {AppBskyModerationDefs, LabelGroupDefinition} from '@atproto/api' -import {useSafeAreaInsets} from 'react-native-safe-area-context' import {atoms as a, useTheme, tokens, native} from '#/alf' import {Text} from '#/components/Typography' @@ -157,59 +156,18 @@ function ModServiceToggle({title}: {title: string}) { ) } -function SubmitViewLoader({ - children, -}: { - children: (props: { - labelers: AppBskyModerationDefs.ModServiceViewDetailed[] - labelGroupToModServiceMap: ReturnType - }) => React.ReactNode -}) { - const { - isLoading: isPreferencesLoading, - error: preferencesError, - data: preferences, - } = usePreferencesQuery() - const { - isLoading: isModServicesLoading, - data: modservices, - error: modservicesError, - } = useModServicesDetailedInfoQuery({ - dids: preferences ? preferences.moderationOpts.mods.map(m => m.did) : [], - }) - const labelGroupToModServiceMap = React.useMemo(() => { - if (!modservices) return {} - return getLabelGroupToLabelerMap(modservices) - }, [modservices]) - - const isLoading = isPreferencesLoading || isModServicesLoading - const error = preferencesError || modservicesError - - return isLoading ? ( - - - - ) : error || !(preferences && modservices) ? null : ( // TODO - children({ - labelers: modservices, - labelGroupToModServiceMap, - }) - ) -} - function SubmitView({ params, selectedLabelGroup, goBack, onSubmitComplete, - labelGroupToModServiceMap, + labelGroupToLabelerMap, }: { params: ReportDialogProps selectedLabelGroup: ReportDialogLabelIds goBack: () => void onSubmitComplete: () => void - labelers: AppBskyModerationDefs.ModServiceViewDetailed[] - labelGroupToModServiceMap: ReturnType + labelGroupToLabelerMap: ReturnType }) { const t = useTheme() const {_} = useLingui() @@ -217,8 +175,10 @@ function SubmitView({ const groupInfoStrings = labelGroupStrings[selectedLabelGroup] const [details, setDetails] = React.useState('') const [submitting, setSubmitting] = React.useState(false) - const [selectedServices, setSelectedServices] = React.useState([]) - const supportedLabelers = labelGroupToModServiceMap[selectedLabelGroup] + const supportedLabelers = labelGroupToLabelerMap[selectedLabelGroup] + const [selectedServices, setSelectedServices] = React.useState( + supportedLabelers?.map(labeler => labeler.creator.did) || [], + ) const submit = React.useCallback(async () => { setSubmitting(true) @@ -347,14 +307,26 @@ function SubmitView({ - + + {!selectedServices.length && ( + + You must select at least one labeler for a report + + )} + @@ -363,16 +335,16 @@ function SubmitView({ ) } -export function ReportDialog({ +export function ReportDialogInner({ params, - cleanup, -}: GlobalDialogProps) { - // REQUIRED CLEANUP - const onClose = React.useCallback(() => cleanup(), [cleanup]) - + labelGroupToLabelerMap, +}: { + params: ReportDialogProps + labelers: AppBskyModerationDefs.ModServiceViewDetailed[] + labelGroupToLabelerMap: ReturnType +}) { const t = useTheme() const {_} = useLingui() - const insets = useSafeAreaInsets() const control = Dialog.useDialogControl() const [selectedLabelGroup, setSelectedLabelGroup] = React.useState< ReportDialogLabelIds | undefined @@ -381,6 +353,9 @@ export function ReportDialog({ const contentGroups = useConfigurableContentLabelGroups() const profileGroups = useConfigurableProfileLabelGroups() const groups = params.type === 'content' ? contentGroups : profileGroups + const filteredGroups = groups.filter(group => { + return Boolean(labelGroupToLabelerMap[group.id]) + }) const i18n = React.useMemo(() => { let title = _(msg`Report this post`) @@ -409,99 +384,144 @@ export function ReportDialog({ ) return ( + <> + {selectedLabelGroup ? ( + setSelectedLabelGroup(undefined)} + onSubmitComplete={control.close} + /> + ) : ( + + + {i18n.title} + + {i18n.description} + + + + + + + {filteredGroups.map(def => { + const strings = labelGroupStrings[def.id] + return ( + + ) + })} + + + + {params.type === 'content' && ( + + + + Need to report a copyright violation? + + + View details + + + + + )} + + + )} + + ) +} + +export function ReportDialog({ + params, + cleanup, +}: GlobalDialogProps) { + // REQUIRED CLEANUP + const onClose = React.useCallback(() => cleanup(), [cleanup]) + const control = Dialog.useDialogControl() + + const { + isLoading: isPreferencesLoading, + error: preferencesError, + data: preferences, + } = usePreferencesQuery() + const { + isLoading: isModServicesLoading, + data: modservices, + error: modservicesError, + } = useModServicesDetailedInfoQuery({ + dids: preferences ? preferences.moderationOpts.mods.map(m => m.did) : [], + }) + const labelGroupToLabelerMap = React.useMemo(() => { + if (!modservices) return {} + return getLabelGroupToLabelerMap(modservices) + }, [modservices]) + + const isLoading = isPreferencesLoading || isModServicesLoading + const error = preferencesError || modservicesError + + return isLoading ? ( + + + + ) : error || !(preferences && modservices) ? null : ( // TODO - {selectedLabelGroup ? ( - - {props => ( - setSelectedLabelGroup(undefined)} - onSubmitComplete={control.close} - /> - )} - - ) : ( - - - {i18n.title} - - {i18n.description} - - - - - - - {groups.map(def => { - const strings = labelGroupStrings[def.id] - return ( - - ) - })} - - - - {params.type === 'content' && ( - - - - Need to report a copyright violation? - - - View details - - - - - )} - - - )} + )