diff --git a/src/components/ModerationLabelPref/PreferenceButton.tsx b/src/components/ModerationLabelPref/PreferenceButton.tsx deleted file mode 100644 index 199b61ed7c..0000000000 --- a/src/components/ModerationLabelPref/PreferenceButton.tsx +++ /dev/null @@ -1,133 +0,0 @@ -import React from 'react' -import {Pressable} from 'react-native' -import {useLingui} from '@lingui/react' -import {msg, Trans} from '@lingui/macro' -import {InterprettedLabelValueDefinition, LabelPreference} from '@atproto/api' - -import { - useLabelBehaviorDescription, - useLabelLongBehaviorDescription, -} from '#/lib/moderation/useLabelBehaviorDescription' - -import {useTheme, atoms as a} from '#/alf' -import * as Dialog from '#/components/Dialog' -import {Text} from '#/components/Typography' -import {Button, ButtonText, ButtonIcon} from '#/components/Button' -import {ArrowTriangleBottom_Stroke2_Corner1_Rounded as ArrowTriangleBottom} from '../icons/ArrowTriangle' -import {Check_Stroke2_Corner0_Rounded as Check} from '../icons/Check' - -export function PreferenceButton({ - name, - pref, - labelValueDefinition, - onSelectPref, -}: { - name: string - pref: LabelPreference - labelValueDefinition: InterprettedLabelValueDefinition - onSelectPref: (pref: LabelPreference) => void -}) { - const {_} = useLingui() - const t = useTheme() - const control = Dialog.useDialogControl() - - const settingDesc = useLabelBehaviorDescription(labelValueDefinition, pref) - const hideLabel = useLabelLongBehaviorDescription( - labelValueDefinition, - 'hide', - ) - const warnLabel = useLabelLongBehaviorDescription( - labelValueDefinition, - 'warn', - ) - const ignoreLabel = useLabelLongBehaviorDescription( - labelValueDefinition, - 'ignore', - ) - const canWarn = !( - labelValueDefinition.blurs === 'none' && - labelValueDefinition.severity === 'none' - ) - - return ( - <> - control.open()} - accessibilityLabel={settingDesc} - accessibilityHint="" - style={[ - a.flex_row, - a.align_center, - a.justify_end, - a.gap_xs, - a.py_xs, - a.rounded_2xs, - ]}> - - {settingDesc} - - - - - - - - - - {name} - - - Choose how this label should be handled. - - - - - {canWarn && ( - - )} - - - - - - ) -} diff --git a/src/components/ModerationLabelPref/PreferenceButton.web.tsx b/src/components/ModerationLabelPref/PreferenceButton.web.tsx deleted file mode 100644 index 8275686241..0000000000 --- a/src/components/ModerationLabelPref/PreferenceButton.web.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import React from 'react' -import {View} from 'react-native' -import {useLingui} from '@lingui/react' -import {msg} from '@lingui/macro' -import {InterprettedLabelValueDefinition, LabelPreference} from '@atproto/api' - -import {useLabelBehaviorDescription} from '#/lib/moderation/useLabelBehaviorDescription' -import { - NativeDropdown, - DropdownItem, -} from '#/view/com/util/forms/NativeDropdown' - -import {useTheme, atoms as a} from '#/alf' -import {Text} from '#/components/Typography' -import {ArrowTriangleBottom_Stroke2_Corner1_Rounded as ArrowTriangleBottom} from '../icons/ArrowTriangle' -import {useInteractionState} from '#/components/hooks/useInteractionState' - -const CHECK_ICON: DropdownItem['icon'] = { - web: ['fas', 'check'], - ios: {name: 'trash'}, //doesnt matter - android: '', -} - -export function PreferenceButton({ - pref, - labelValueDefinition, - onSelectPref, -}: { - pref: LabelPreference - labelValueDefinition: InterprettedLabelValueDefinition - onSelectPref: (pref: LabelPreference) => void -}) { - const {_} = useLingui() - const t = useTheme() - - const { - state: hovered, - onIn: onHoverIn, - onOut: onHoverOut, - } = useInteractionState() - - const settingDesc = useLabelBehaviorDescription(labelValueDefinition, pref) - const hideLabel = useLabelBehaviorDescription(labelValueDefinition, 'hide') - const warnLabel = useLabelBehaviorDescription(labelValueDefinition, 'warn') - const ignoreLabel = useLabelBehaviorDescription( - labelValueDefinition, - 'ignore', - ) - const canWarn = !( - labelValueDefinition.blurs === 'none' && - labelValueDefinition.severity === 'none' - ) - - const dropdownItems: DropdownItem[] = [] - dropdownItems.push({ - icon: pref === 'hide' ? CHECK_ICON : undefined, - label: hideLabel, - onPress: () => onSelectPref('hide'), - }) - if (canWarn) { - dropdownItems.push({ - icon: pref === 'warn' ? CHECK_ICON : undefined, - label: warnLabel, - onPress: () => onSelectPref('warn'), - }) - } - dropdownItems.push({ - icon: pref === 'ignore' ? CHECK_ICON : undefined, - label: ignoreLabel, - onPress: () => onSelectPref('ignore'), - }) - - return ( - - - - {settingDesc} - - - - - ) -} diff --git a/src/components/ModerationLabelPref/index.tsx b/src/components/ModerationLabelPref/index.tsx index f80e6d8387..e8c1c66d5c 100644 --- a/src/components/ModerationLabelPref/index.tsx +++ b/src/components/ModerationLabelPref/index.tsx @@ -1,8 +1,14 @@ import React from 'react' -import {View} from 'react-native' +import {Pressable, View} from 'react-native' import {InterprettedLabelValueDefinition, LabelPreference} from '@atproto/api' +import {useLingui} from '@lingui/react' +import {msg, Trans} from '@lingui/macro' import {useLabelStrings} from '#/lib/moderation/useLabelStrings' +import { + useLabelBehaviorDescription, + useLabelLongBehaviorDescription, +} from '#/lib/moderation/useLabelBehaviorDescription' import { usePreferencesQuery, usePreferencesSetContentLabelMutation, @@ -10,7 +16,10 @@ import { import {useTheme, atoms as a} from '#/alf' import {Text} from '#/components/Typography' -import {PreferenceButton} from './PreferenceButton' +import * as Dialog from '#/components/Dialog' +import {Button, ButtonText, ButtonIcon} from '#/components/Button' +import {ArrowTriangleBottom_Stroke2_Corner1_Rounded as ArrowTriangleBottom} from '../icons/ArrowTriangle' +import {Check_Stroke2_Corner0_Rounded as Check} from '../icons/Check' export function ModerationLabelPref({ labelValueDefinition, @@ -21,12 +30,35 @@ export function ModerationLabelPref({ labelerDid: string | undefined disabled?: boolean }) { + const {_} = useLingui() const t = useTheme() - const allLabelStrings = useLabelStrings() - const {data: preferences} = usePreferencesQuery() - const {mutate, variables} = usePreferencesSetContentLabelMutation() + const control = Dialog.useDialogControl() const {identifier} = labelValueDefinition + const {data: preferences} = usePreferencesQuery() + const {mutate, variables} = usePreferencesSetContentLabelMutation() + const savedPref = labelerDid + ? preferences?.moderationPrefs.mods.find(m => m.did === labelerDid)?.labels[ + identifier + ] + : preferences?.moderationPrefs.labels[identifier] + const pref = variables?.visibility ?? savedPref ?? 'warn' + + const settingDesc = useLabelBehaviorDescription(labelValueDefinition, pref) + const hideLabel = useLabelLongBehaviorDescription( + labelValueDefinition, + 'hide', + ) + const warnLabel = useLabelLongBehaviorDescription( + labelValueDefinition, + 'warn', + ) + const ignoreLabel = useLabelLongBehaviorDescription( + labelValueDefinition, + 'ignore', + ) + + const allLabelStrings = useLabelStrings() const labelStrings = labelValueDefinition.locales[0] // TODO look up locale ? labelValueDefinition.locales[0] : labelValueDefinition.identifier in allLabelStrings @@ -36,34 +68,141 @@ export function ModerationLabelPref({ description: `Labeled "${labelValueDefinition.identifier}"`, } - const savedPref = labelerDid - ? preferences?.moderationPrefs.mods.find(m => m.did === labelerDid)?.labels[ - identifier - ] - : preferences?.moderationPrefs.labels[identifier] - const pref = variables?.visibility ?? savedPref ?? 'warn' + const canWarn = !( + labelValueDefinition.blurs === 'none' && + labelValueDefinition.severity === 'none' + ) const onSelectPref = (newPref: LabelPreference) => mutate({label: identifier, visibility: newPref, labelerDid}) return ( - - + <> + control.open()} + accessibilityLabel={settingDesc} + accessibilityHint="" + style={[ + a.flex_row, + a.justify_between, + a.gap_sm, + a.align_center, + t.atoms.bg_contrast_50, + a.px_lg, + a.py_lg, + a.rounded_sm, + ]}> {labelStrings.name} - + + {labelStrings.description} - - {!disabled && ( - + + {!disabled && ( + + {settingDesc} + + )} + + )} - - + + + + + + + + {labelStrings.name} + + + {labelStrings.description} + + {disabled ? ( + + ) : ( + <> + + + {canWarn && ( + + )} + + + + )} + + + ) } diff --git a/src/screens/Profile/Sections/Labels.tsx b/src/screens/Profile/Sections/Labels.tsx index 63a75900ee..6e203f57ef 100644 --- a/src/screens/Profile/Sections/Labels.tsx +++ b/src/screens/Profile/Sections/Labels.tsx @@ -141,8 +141,6 @@ export function ProfileLabelsSectionInner({ ) as InterprettedLabelValueDefinition[] }, [labelerInfo, labelValues]) - console.log(headerHeight, scrollElRef.current) - return ( {labelDefs.length > 0 && ( - - {labelDefs.map((labelDef, i) => { + + {labelDefs.map(labelDef => { return ( - - {i !== 0 && } - - - - + ) })}