From 697b262ba4008f0f891f67a436e5c7a6b4dc97a4 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 27 Feb 2024 14:33:57 -0800 Subject: [PATCH] Experiment to put labeling under a tab of a normal profile --- src/screens/Profile/Header/Handle.tsx | 7 -- src/screens/Profile/Header/index.tsx | 12 +-- .../Profile/Sections/ContentFilters.tsx | 79 ++++++++++++++++--- src/view/screens/Profile.tsx | 41 +++++----- 4 files changed, 94 insertions(+), 45 deletions(-) diff --git a/src/screens/Profile/Header/Handle.tsx b/src/screens/Profile/Header/Handle.tsx index 53961c961d..ea3272b14c 100644 --- a/src/screens/Profile/Header/Handle.tsx +++ b/src/screens/Profile/Header/Handle.tsx @@ -43,13 +43,6 @@ export function ProfileHeaderHandle({ ]}> {invalidHandle ? ⚠Invalid Handle : `@${profile.handle}`} - {profile.associated?.modservice ? ( - - - Moderation service - - - ) : undefined} ) } diff --git a/src/screens/Profile/Header/index.tsx b/src/screens/Profile/Header/index.tsx index 70f655e46a..a2daf31b0b 100644 --- a/src/screens/Profile/Header/index.tsx +++ b/src/screens/Profile/Header/index.tsx @@ -42,12 +42,12 @@ interface Props { } let ProfileHeader = (props: Props): React.ReactNode => { - if (props.profile.associated?.modservice) { - if (!props.modservice) { - return - } - return - } + // if (props.profile.associated?.modservice) { + // if (!props.modservice) { + // return + // } + // return + // } return } ProfileHeader = memo(ProfileHeader) diff --git a/src/screens/Profile/Sections/ContentFilters.tsx b/src/screens/Profile/Sections/ContentFilters.tsx index a1def38a44..31e678cff7 100644 --- a/src/screens/Profile/Sections/ContentFilters.tsx +++ b/src/screens/Profile/Sections/ContentFilters.tsx @@ -5,13 +5,15 @@ import {Trans, msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useSafeAreaFrame} from 'react-native-safe-area-context' -import {useSetTitle} from '#/lib/hooks/useSetTitle' +import {useModServiceSubscriptionMutation} from '#/state/queries/modservice' import {getLabelGroupsFromLabels} from '#/lib/moderation' +import {logger} from '#/logger' import {useTheme, atoms as a} from '#/alf' import {Text} from '#/components/Typography' import {Loader} from '#/components/Loader' import {Divider} from '#/components/Divider' +import {Button, ButtonText} from '#/components/Button' import {CenteredView, ScrollView} from '#/view/com/util/Views' import {ErrorState} from '../ErrorState' import {ModerationLabelPref} from '#/components/ModerationLabelPref' @@ -72,6 +74,7 @@ export function ProfileContentFiltersSectionInner({ moderationOpts: ModerationOpts modservice: AppBskyModerationDefs.ModServiceViewDetailed }) { + const {_} = useLingui() const t = useTheme() const groups = React.useMemo(() => { return getLabelGroupsFromLabels(modservice.policies.labelValues).filter( @@ -83,8 +86,25 @@ export function ProfileContentFiltersSectionInner({ mod => mod.did === modservice.creator.did && mod.enabled, ), ) + const hasSession = true // TODO - useSetTitle(modservice.creator.displayName || modservice.creator.handle) + const {mutateAsync: toggleSubscription, variables} = + useModServiceSubscriptionMutation() + const isSubscribed = + variables?.subscribe ?? + moderationOpts.mods.find(mod => mod.did === modservice.creator.did) + + const onPressSubscribe = React.useCallback(async () => { + try { + await toggleSubscription({ + did: modservice.creator.did, + subscribe: !isSubscribed, + }) + } catch (e: any) { + // setSubscriptionError(e.message) + logger.error(`Failed to subscribe to labeler`, {message: e.message}) + } + }, [toggleSubscription, isSubscribed, modservice]) return ( - - This service labels the following types of content. - + + + + + Labels are annotations on users and content. They can be used to + hide, warn, and categorize the network. + + + {!isSubscribed && ( + + + Subscribe to use these labels from @{modservice.creator.handle}: + + + )} + + + + + 0) const showListsTab = @@ -490,12 +489,12 @@ function ProfileScreenLoadedV2({ const sectionTitles = useMemo(() => { return [ - showFiltersTab ? _(msg`Content filters`) : undefined, showPostsTab ? _(msg`Posts`) : undefined, showRepliesTab ? _(msg`Replies`) : undefined, showMediaTab ? _(msg`Media`) : undefined, showLikesTab ? _(msg`Likes`) : undefined, showFeedsTab ? _(msg`Feeds`) : undefined, + showFiltersTab ? _(msg`Labels`) : undefined, showListsTab ? _(msg`Lists`) : undefined, ].filter(Boolean) as string[] }, [ @@ -511,9 +510,6 @@ function ProfileScreenLoadedV2({ let nextIndex = 0 let filtersIndex: number | null = null - if (showFiltersTab) { - filtersIndex = nextIndex++ - } let postsIndex: number | null = null if (showPostsTab) { postsIndex = nextIndex++ @@ -534,6 +530,9 @@ function ProfileScreenLoadedV2({ if (showFeedsTab) { feedsIndex = nextIndex++ } + if (showFiltersTab) { + filtersIndex = nextIndex++ + } let listsIndex: number | null = null if (showListsTab) { listsIndex = nextIndex++ @@ -651,18 +650,6 @@ function ProfileScreenLoadedV2({ onPageSelected={onPageSelected} onCurrentPageSelected={onCurrentPageSelected} renderHeader={renderHeader}> - {showFiltersTab - ? ({headerHeight, isFocused, scrollElRef}) => ( - - ) - : null} {showPostsTab ? ({headerHeight, isFocused, scrollElRef}) => ( ) : null} + {showFiltersTab + ? ({headerHeight, isFocused, scrollElRef}) => ( + + ) + : null} {showListsTab ? ({headerHeight, isFocused, scrollElRef}) => (