add admonition for cleanup
This commit is contained in:
@@ -5,13 +5,14 @@ import {msg, Trans} from '@lingui/macro'
|
|||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useFocusEffect} from '@react-navigation/native'
|
import {useFocusEffect} from '@react-navigation/native'
|
||||||
|
|
||||||
import {getLabelingServiceTitle} from '#/lib/moderation'
|
import {getLabelingServiceTitle, isAppLabeler} from '#/lib/moderation'
|
||||||
import {
|
import {
|
||||||
type CommonNavigatorParams,
|
type CommonNavigatorParams,
|
||||||
type NativeStackScreenProps,
|
type NativeStackScreenProps,
|
||||||
} from '#/lib/routes/types'
|
} from '#/lib/routes/types'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {useIsBirthdateUpdateAllowed} from '#/state/birthdate'
|
import {useIsBirthdateUpdateAllowed} from '#/state/birthdate'
|
||||||
|
import {useRemoveLabelersMutation} from '#/state/queries/labeler'
|
||||||
import {
|
import {
|
||||||
useMyLabelersQuery,
|
useMyLabelersQuery,
|
||||||
usePreferencesQuery,
|
usePreferencesQuery,
|
||||||
@@ -21,10 +22,10 @@ import {
|
|||||||
import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities'
|
import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities'
|
||||||
import {useSetMinimalShellMode} from '#/state/shell'
|
import {useSetMinimalShellMode} from '#/state/shell'
|
||||||
import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf'
|
||||||
import {Admonition} from '#/components/Admonition'
|
import * as Admonition from '#/components/Admonition'
|
||||||
import {AgeAssuranceAdmonition} from '#/components/ageAssurance/AgeAssuranceAdmonition'
|
import {AgeAssuranceAdmonition} from '#/components/ageAssurance/AgeAssuranceAdmonition'
|
||||||
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
||||||
import {Button} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
||||||
import {Divider} from '#/components/Divider'
|
import {Divider} from '#/components/Divider'
|
||||||
import * as Toggle from '#/components/forms/Toggle'
|
import * as Toggle from '#/components/forms/Toggle'
|
||||||
@@ -42,6 +43,7 @@ import {InlineLinkText, Link} from '#/components/Link'
|
|||||||
import {ListMaybePlaceholder} from '#/components/Lists'
|
import {ListMaybePlaceholder} from '#/components/Lists'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {GlobalLabelPreference} from '#/components/moderation/LabelPreference'
|
import {GlobalLabelPreference} from '#/components/moderation/LabelPreference'
|
||||||
|
import * as toast from '#/components/Toast'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {useAgeAssurance} from '#/ageAssurance'
|
import {useAgeAssurance} from '#/ageAssurance'
|
||||||
import {IS_IOS} from '#/env'
|
import {IS_IOS} from '#/env'
|
||||||
@@ -166,10 +168,34 @@ export function ModerationScreenInner({
|
|||||||
data: labelers,
|
data: labelers,
|
||||||
error: labelersError,
|
error: labelersError,
|
||||||
} = useMyLabelersQuery()
|
} = useMyLabelersQuery()
|
||||||
|
const {mutateAsync: removeLabelers, isPending: isRemovingLabelers} =
|
||||||
|
useRemoveLabelersMutation()
|
||||||
const aa = useAgeAssurance()
|
const aa = useAgeAssurance()
|
||||||
const isBirthdateUpdateAllowed = useIsBirthdateUpdateAllowed()
|
const isBirthdateUpdateAllowed = useIsBirthdateUpdateAllowed()
|
||||||
const aaCopy = useAgeAssuranceCopy()
|
const aaCopy = useAgeAssuranceCopy()
|
||||||
|
|
||||||
|
const subscribedDids = preferences.moderationPrefs.labelers.map(l => l.did)
|
||||||
|
const returnedDids = new Set(labelers?.map(l => l.creator.did))
|
||||||
|
const unavailableDids = subscribedDids.filter(
|
||||||
|
did =>
|
||||||
|
!returnedDids.has(did) &&
|
||||||
|
!isAppLabeler(did) &&
|
||||||
|
!isNonConfigurableModerationAuthority(did),
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleCleanup = async () => {
|
||||||
|
try {
|
||||||
|
await removeLabelers({dids: unavailableDids})
|
||||||
|
toast.show(_(msg`Removed unavailable services`), {
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
} catch (e: any) {
|
||||||
|
logger.error('Failed to remove unavailable labelers', {
|
||||||
|
safeMessage: e.message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
setMinimalShellMode(false)
|
setMinimalShellMode(false)
|
||||||
@@ -209,7 +235,7 @@ export function ModerationScreenInner({
|
|||||||
<View style={[a.pt_2xl, a.px_lg, gtMobile && a.px_2xl]}>
|
<View style={[a.pt_2xl, a.px_lg, gtMobile && a.px_2xl]}>
|
||||||
{aa.flags.adultContentDisabled && isBirthdateUpdateAllowed && (
|
{aa.flags.adultContentDisabled && isBirthdateUpdateAllowed && (
|
||||||
<View style={[a.pb_2xl]}>
|
<View style={[a.pb_2xl]}>
|
||||||
<Admonition type="tip" style={[a.pb_md]}>
|
<Admonition.Admonition type="tip" style={[a.pb_md]}>
|
||||||
<Trans>
|
<Trans>
|
||||||
Your declared age is under 18. Some settings below may be
|
Your declared age is under 18. Some settings below may be
|
||||||
disabled. If this was a mistake, you may edit your birthdate in
|
disabled. If this was a mistake, you may edit your birthdate in
|
||||||
@@ -221,7 +247,7 @@ export function ModerationScreenInner({
|
|||||||
</InlineLinkText>
|
</InlineLinkText>
|
||||||
.
|
.
|
||||||
</Trans>
|
</Trans>
|
||||||
</Admonition>
|
</Admonition.Admonition>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -439,6 +465,34 @@ export function ModerationScreenInner({
|
|||||||
<Trans>Advanced</Trans>
|
<Trans>Advanced</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
|
{unavailableDids.length > 0 && (
|
||||||
|
<Admonition.Outer type="tip" style={[a.mb_md]}>
|
||||||
|
<Admonition.Row>
|
||||||
|
<Admonition.Icon />
|
||||||
|
<Admonition.Content>
|
||||||
|
<Admonition.Text>
|
||||||
|
<Trans>
|
||||||
|
Some moderation services in your list are no longer available.
|
||||||
|
</Trans>
|
||||||
|
</Admonition.Text>
|
||||||
|
</Admonition.Content>
|
||||||
|
<Admonition.Button
|
||||||
|
color="primary_subtle"
|
||||||
|
label={_(msg`Remove unavailable moderation services`)}
|
||||||
|
onPress={handleCleanup}
|
||||||
|
disabled={isRemovingLabelers}>
|
||||||
|
{isRemovingLabelers ? (
|
||||||
|
<Loader size="xs" />
|
||||||
|
) : (
|
||||||
|
<ButtonText>
|
||||||
|
<Trans>Remove</Trans>
|
||||||
|
</ButtonText>
|
||||||
|
)}
|
||||||
|
</Admonition.Button>
|
||||||
|
</Admonition.Row>
|
||||||
|
</Admonition.Outer>
|
||||||
|
)}
|
||||||
|
|
||||||
{isLabelersLoading ? (
|
{isLabelersLoading ? (
|
||||||
<View style={[a.w_full, a.align_center, a.p_lg]}>
|
<View style={[a.w_full, a.align_center, a.p_lg]}>
|
||||||
<Loader size="xl" />
|
<Loader size="xl" />
|
||||||
|
|||||||
@@ -82,6 +82,22 @@ export function useLabelersDetailedInfoQuery({dids}: {dids: string[]}) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useRemoveLabelersMutation() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const agent = useAgent()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
async mutationFn({dids}: {dids: string[]}) {
|
||||||
|
await Promise.all(dids.map(did => agent.removeLabeler(did)))
|
||||||
|
},
|
||||||
|
async onSuccess() {
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: preferencesQueryKey,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function useLabelerSubscriptionMutation() {
|
export function useLabelerSubscriptionMutation() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
|||||||
Reference in New Issue
Block a user