diff --git a/src/view/screens/DebugMod.tsx b/src/view/screens/DebugMod.tsx index 144d8c25f7..7009966f2f 100644 --- a/src/view/screens/DebugMod.tsx +++ b/src/view/screens/DebugMod.tsx @@ -10,11 +10,12 @@ import { AppBskyActorDefs, AppBskyFeedDefs, AppBskyFeedPost, - LabelTarget, LabelPreference, ModerationDecision, ModerationBehavior, RichText, + ComAtprotoLabelDefs, + interpretLabelValueDefinition, } from '@atproto/api' import {moderationOptsOverrideContext} from '#/state/queries/preferences' import {useSession} from '#/state/session' @@ -30,6 +31,7 @@ import {H1, H3, P, Text} from '#/components/Typography' import {useLabelStrings} from '#/lib/moderation/useLabelStrings' import * as Toggle from '#/components/forms/Toggle' import * as ToggleButton from '#/components/forms/ToggleButton' +import * as TextField from '#/components/forms/TextField' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import { @@ -42,22 +44,12 @@ import {ProfileCard} from '../com/profile/ProfileCard' import {FeedItem} from '../com/posts/FeedItem' import {FeedItem as NotifFeedItem} from '../com/notifications/FeedItem' import {PostThreadItem} from '../com/post-thread/PostThreadItem' +import {Divider} from '#/components/Divider' const LABEL_VALUES: (keyof typeof LABELS)[] = Object.keys( LABELS, ) as (keyof typeof LABELS)[] -const MOCK_MOD_PREFS = { - adultContentEnabled: true, - labelGroups: {}, - mods: [ - { - did: 'did:plc:fake-labeler', - labels: {}, - }, - ], -} - export const DebugModScreen = ({}: NativeStackScreenProps< CommonNavigatorParams, 'DebugMod' @@ -68,6 +60,20 @@ export const DebugModScreen = ({}: NativeStackScreenProps< const [label, setLabel] = React.useState([LABEL_VALUES[0]]) const [target, setTarget] = React.useState(['account']) const [visibility, setVisiblity] = React.useState(['hide']) + const [customLabelDef, setCustomLabelDef] = + React.useState({ + identifier: 'x-custom', + blurs: 'content', + severity: 'alert', + locales: [ + { + lang: 'en', + name: 'Custom label', + description: 'A custom label created in this test environment', + }, + ], + }) + const [view, setView] = React.useState(['post']) const labelStrings = useLabelStrings() const {currentAccount} = useSession() @@ -226,14 +232,22 @@ export const DebugModScreen = ({}: NativeStackScreenProps< return { userDid: isLoggedOut ? '' : isTargetMe ? did : 'did:web:alice.test', prefs: { - ...MOCK_MOD_PREFS, adultContentEnabled: !noAdult, labels: { [label[0]]: visibility[0] as LabelPreference, }, + mods: [ + { + did: 'did:plc:fake-labeler', + labels: {[label[0]]: visibility[0] as LabelPreference}, + }, + ], + }, + labelDefs: { + 'did:plc:fake-labeler': [interpretLabelValueDefinition(customLabelDef)], }, } - }, [label, visibility, noAdult, isLoggedOut, isTargetMe, did]) + }, [label, visibility, noAdult, isLoggedOut, isTargetMe, did, customLabelDef]) const profileModeration = React.useMemo(() => { return moderateProfile(profile, modOpts) @@ -248,8 +262,6 @@ export const DebugModScreen = ({}: NativeStackScreenProps<

Moderation states

- - - - - - - Target is me - - - - Following target - - - - Self label - - - - Adult disabled - - - - Logged out - + + + + {LABEL_VALUES.map(labelValue => { + let targetFixed = target[0] + if ( + targetFixed !== 'account' && + targetFixed !== 'profile' + ) { + targetFixed = 'content' + } + const disabled = + isSelfLabel && + LABELS[labelValue].flags.includes('no-self') + return ( + + + {labelValue} + + ) + })} + + + Custom label + + + + + {label[0] === 'x-custom' && ( + + )} + + + + + + Target is me + + + + Following target + + + + Self label + + + + Adult disabled + + + + Logged out + + + + + + + + + Target + + + + + + + Account + + + + Profile + + + + Post + + + + Embed + + + + - - - - - - - Account - - - Profile - - - Post - - - Embed - - - - - - - - - Hide - - - Warn - - - Ignore - - - - - - - - - {LABEL_VALUES.map(labelValue => { - let targetFixed = target[0] - if ( - targetFixed !== 'account' && - targetFixed !== 'profile' - ) { - targetFixed = 'content' - } - const disabled = - isSelfLabel && - LABELS[labelValue].flags.includes('no-self') - return ( - - - {labelValue} - - ) - })} - - + {LABELS[label[0] as keyof typeof LABELS]?.configurable !== + false && ( + + + Preference + + + + + + + Hide + + + + Warn + + + + Ignore + + + + + + )} + )} - - + - + + + Post + + + Notifications + + + Account + + + Data + + - - + + {view[0] === 'post' && ( + <> + + - + + - - + + + + )} - + {view[0] === 'notifications' && ( + <> + + - - + - + + + + )} - {(target[0] === 'account' || target[0] === 'profile') && ( - <> - - + {view[0] === 'account' && ( + <> + + - + - - + + + + )} - - - - - - - - )} - - - - - - + {view[0] === 'data' && ( + <> + + + + + + + )} +
@@ -451,6 +585,101 @@ function Heading({title, subtitle}: {title: string; subtitle?: string}) { ) } +function CustomLabelForm({ + def, + setDef, +}: { + def: ComAtprotoLabelDefs.LabelValueDefinition + setDef: React.Dispatch< + React.SetStateAction + > +}) { + const t = useTheme() + return ( + + + + Blurs + + + setDef(v => ({...v, blurs: values[0]}))}> + + + + Content + + + + Media + + + + None + + + + + + + + Severity + + + setDef(v => ({...v, severity: values[0]}))}> + + + + Alert + + + + Inform + + + + None + + + + + + + ) +} + function Toggler({label, children}: React.PropsWithChildren<{label: string}>) { const t = useTheme() const [show, setShow] = React.useState(false)