From 09dfc9edf820396ba0132e89ed6d98c2a4231d5d Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 5 Jul 2024 20:17:47 +0100 Subject: Show feedback for Follow button in interstitials (#4738) * Fix Follow in interstitials * Show feedback in toast --- src/components/FeedInterstitials.tsx | 1 + src/components/ProfileCard.tsx | 25 ++++++++++++++++++++++++- src/state/queries/profile.ts | 19 +++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/FeedInterstitials.tsx b/src/components/FeedInterstitials.tsx index 501eac57e..243db0a49 100644 --- a/src/components/FeedInterstitials.tsx +++ b/src/components/FeedInterstitials.tsx @@ -212,6 +212,7 @@ export function SuggestedFollows() { /> - + @@ -273,11 +278,13 @@ export function FollowButton(props: FollowButtonProps) { export function FollowButtonInner({ profile: profileUnshadowed, + moderationOpts, logContext, ...rest }: FollowButtonProps) { const {_} = useLingui() const profile = useProfileShadow(profileUnshadowed) + const moderation = moderateProfile(profile, moderationOpts) const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue( profile, logContext, @@ -289,6 +296,14 @@ export function FollowButtonInner({ e.stopPropagation() try { await queueFollow() + Toast.show( + _( + msg`Following ${sanitizeDisplayName( + profile.displayName || profile.handle, + moderation.ui('displayName'), + )}`, + ), + ) } catch (e: any) { if (e?.name !== 'AbortError') { Toast.show(_(msg`An issue occurred, please try again.`)) @@ -301,6 +316,14 @@ export function FollowButtonInner({ e.stopPropagation() try { await queueUnfollow() + Toast.show( + _( + msg`No longer following ${sanitizeDisplayName( + profile.displayName || profile.handle, + moderation.ui('displayName'), + )}`, + ), + ) } catch (e: any) { if (e?.name !== 'AbortError') { Toast.show(_(msg`An issue occurred, please try again.`)) diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index d9a2c6bbb..1f866d26d 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -3,6 +3,7 @@ import {Image as RNImage} from 'react-native-image-crop-picker' import { AppBskyActorDefs, AppBskyActorGetProfile, + AppBskyActorGetProfiles, AppBskyActorProfile, AtUri, BskyAgent, @@ -516,11 +517,11 @@ export function* findAllProfilesInQueryData( queryClient: QueryClient, did: string, ): Generator { - const queryDatas = + const profileQueryDatas = queryClient.getQueriesData({ queryKey: [RQKEY_ROOT], }) - for (const [_queryKey, queryData] of queryDatas) { + for (const [_queryKey, queryData] of profileQueryDatas) { if (!queryData) { continue } @@ -528,6 +529,20 @@ export function* findAllProfilesInQueryData( yield queryData } } + const profilesQueryDatas = + queryClient.getQueriesData({ + queryKey: [profilesQueryKeyRoot], + }) + for (const [_queryKey, queryData] of profilesQueryDatas) { + if (!queryData) { + continue + } + for (let profile of queryData.profiles) { + if (profile.did === did) { + yield profile + } + } + } } export function findProfileQueryData( -- cgit 1.4.1