diff options
author | dan <dan.abramov@gmail.com> | 2024-07-05 20:17:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-05 20:17:47 +0100 |
commit | 09dfc9edf820396ba0132e89ed6d98c2a4231d5d (patch) | |
tree | 10e60cdfddff5fe497cd31a274cd725db7671f49 /src | |
parent | d5fd19df8fa2e235febb357845be534415bec218 (diff) | |
download | voidsky-09dfc9edf820396ba0132e89ed6d98c2a4231d5d.tar.zst |
Show feedback for Follow button in interstitials (#4738)
* Fix Follow in interstitials * Show feedback in toast
Diffstat (limited to 'src')
-rw-r--r-- | src/components/FeedInterstitials.tsx | 1 | ||||
-rw-r--r-- | src/components/ProfileCard.tsx | 25 | ||||
-rw-r--r-- | src/state/queries/profile.ts | 19 |
3 files changed, 42 insertions, 3 deletions
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() { /> <ProfileCard.FollowButton profile={profile} + moderationOpts={moderationOpts} logContext="FeedInterstitial" color="secondary_inverted" shape="round" diff --git a/src/components/ProfileCard.tsx b/src/components/ProfileCard.tsx index 77016d4fe..79f1108cb 100644 --- a/src/components/ProfileCard.tsx +++ b/src/components/ProfileCard.tsx @@ -62,7 +62,11 @@ export function Card({ <Header> <Avatar profile={profile} moderationOpts={moderationOpts} /> <NameAndHandle profile={profile} moderationOpts={moderationOpts} /> - <FollowButton profile={profile} logContext={logContext} /> + <FollowButton + profile={profile} + moderationOpts={moderationOpts} + logContext={logContext} + /> </Header> <ProfileCardPills @@ -261,6 +265,7 @@ export function DescriptionPlaceholder() { export type FollowButtonProps = { profile: AppBskyActorDefs.ProfileViewBasic + moderationOpts: ModerationOpts logContext: LogEvents['profile:follow']['logContext'] & LogEvents['profile:unfollow']['logContext'] } & Partial<ButtonProps> @@ -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<AppBskyActorDefs.ProfileViewDetailed, void> { - const queryDatas = + const profileQueryDatas = queryClient.getQueriesData<AppBskyActorDefs.ProfileViewDetailed>({ 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<AppBskyActorGetProfiles.OutputSchema>({ + 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( |