Rough enablement

This commit is contained in:
Eric Bailey
2024-02-13 15:40:32 -06:00
parent 78acf4c86e
commit da735f4894
3 changed files with 79 additions and 28 deletions
@@ -2,24 +2,45 @@ import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {LABEL_GROUPS, AppBskyModerationDefs} from '@atproto/api'
// TODO
import {ModPrefItem} from '@atproto/api/dist/client/types/app/bsky/actor/defs'
import {useLabelGroupStrings} from '#/lib/moderation/useLabelGroupStrings' import {useLabelGroupStrings} from '#/lib/moderation/useLabelGroupStrings'
import {useModServiceLabelGroupEnableMutation} from '#/state/queries/modservice'
import {useTheme, atoms as a} from '#/alf' import {useTheme, atoms as a} from '#/alf'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import * as ToggleButton from '#/components/forms/ToggleButton' import * as Toggle from '#/components/forms/Toggle'
export function PreferenceRow({labelGroup}: {labelGroup: string}) { export function PreferenceRow({
labelGroup,
modservicePreferences,
}: {
labelGroup: keyof typeof LABEL_GROUPS
modservicePreferences?: ModPrefItem
}) {
const t = useTheme() const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
const labelGroupStrings = useLabelGroupStrings() const labelGroupStrings = useLabelGroupStrings()
const groupInfoStrings = labelGroupStrings[labelGroup] const groupInfoStrings = labelGroupStrings[labelGroup]
const {mutateAsync, variables} = useModServiceLabelGroupEnableMutation()
const enabled =
variables?.enabled ??
!modservicePreferences?.disabledLabelGroups?.includes(labelGroup)
const labels = { const onToggleEnabled = React.useCallback(async () => {
hide: _(msg`Hide`), try {
warn: _(msg`Warn`), await mutateAsync({
show: _(msg`Show`), // @ts-ignore TODO
} did: modservicePreferences?.did,
group: labelGroup,
enabled: !enabled,
})
} catch (e: any) {
console.error(e)
}
}, [mutateAsync, enabled])
return ( return (
<View <View
@@ -28,7 +49,6 @@ export function PreferenceRow({labelGroup}: {labelGroup: string}) {
a.justify_between, a.justify_between,
a.gap_sm, a.gap_sm,
a.py_xs, a.py_xs,
a.px_xs,
a.align_center, a.align_center,
]}> ]}>
<View style={[a.gap_xs, {width: '50%'}]}> <View style={[a.gap_xs, {width: '50%'}]}>
@@ -38,22 +58,16 @@ export function PreferenceRow({labelGroup}: {labelGroup: string}) {
</Text> </Text>
</View> </View>
<View style={[a.justify_center, {minHeight: 35}]}> <View style={[a.justify_center, {minHeight: 35}]}>
<ToggleButton.Group {modservicePreferences && (
label={_( <Toggle.Item
msg`Configure content filtering setting for category: ${groupInfoStrings.name.toLowerCase()}`, name="enable"
)} value={enabled}
values={['warn']} onChange={onToggleEnabled}
onChange={() => {}}> label="Enable">
<ToggleButton.Button name="hide" label={labels.hide}> <Toggle.Label>{enabled ? 'Enabled' : 'Disabled'}</Toggle.Label>
{labels.hide} <Toggle.Switch />
</ToggleButton.Button> </Toggle.Item>
<ToggleButton.Button name="warn" label={labels.warn}> )}
{labels.warn}
</ToggleButton.Button>
<ToggleButton.Button name="ignore" label={labels.show}>
{labels.show}
</ToggleButton.Button>
</ToggleButton.Group>
</View> </View>
</View> </View>
) )
+25 -4
View File
@@ -143,6 +143,11 @@ export function ProfileModserviceScreenInner({
def => def.configurable, def => def.configurable,
) )
}, [modservice.policies.labelValues]) }, [modservice.policies.labelValues])
const modservicePreferences = React.useMemo(() => {
return preferences.moderationOpts.mods.find(
p => p.did === modservice.creator.did,
)
}, [modservice.creator.did, preferences.moderationOpts.mods])
useSetTitle(modservice.creator.displayName || modservice.creator.handle) useSetTitle(modservice.creator.displayName || modservice.creator.handle)
@@ -179,7 +184,7 @@ export function ProfileModserviceScreenInner({
}}> }}>
<Header modservice={modservice} preferences={preferences} /> <Header modservice={modservice} preferences={preferences} />
<View style={[a.gap_md]}> <View style={[a.gap_md, a.pb_xl]}>
{modservice.description ? ( {modservice.description ? (
<RichText <RichText
testID="modinfoDescription" testID="modinfoDescription"
@@ -248,12 +253,28 @@ export function ProfileModserviceScreenInner({
</View> </View>
</View> </View>
<Divider />
<View style={[a.gap_sm, a.mt_xl]}>
<Text style={[a.text_md, a.font_bold]}>
Configure moderation service
</Text>
<Text style={[t.atoms.text_contrast_high, a.leading_snug]}>
This moderation service supports the following types of content.
Configure which types of content you'd like to respect from this
service.
</Text>
</View>
<View style={[a.gap_md, a.mt_xl]}> <View style={[a.gap_md, a.mt_xl]}>
{groups.map(def => { {groups.map((def, i) => {
return ( return (
<React.Fragment key={def.id}> <React.Fragment key={def.id}>
<Divider /> {i !== 0 && <Divider />}
<PreferenceRow labelGroup={def.id} /> <PreferenceRow
labelGroup={def.id}
modservicePreferences={modservicePreferences}
/>
</React.Fragment> </React.Fragment>
) )
})} })}
+16
View File
@@ -48,3 +48,19 @@ export function useModServiceEnableMutation() {
}, },
}) })
} }
export function useModServiceLabelGroupEnableMutation() {
const queryClient = useQueryClient()
return useMutation({
async mutationFn({did, group, enabled}: {did: string; group: string, enabled: boolean}) {
console.log('useModServiceLabelGroupEnableMutation', did, group, enabled)
await getAgent().setModServiceLabelGroupEnabled(did, group, enabled)
},
onSuccess() {
queryClient.invalidateQueries({
queryKey: preferencesQueryKey,
})
},
})
}