From 2fe6d1b5cd71da365bd89c0a22fd98e3eef7acae Mon Sep 17 00:00:00 2001 From: Kris Urbas <605420+krzysu@users.noreply.github.com> Date: Mon, 13 May 2024 17:27:25 +0200 Subject: [PATCH] fix: refresh profile following after a follow or unfollow --- .changeset/grumpy-bottles-relate.md | 7 +++++++ packages/react/src/shared.tsx | 7 +++++-- .../adapters/responders/FollowProfileResponder.ts | 13 +++++++++++-- .../adapters/responders/UnfollowProfileResponder.ts | 13 +++++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 .changeset/grumpy-bottles-relate.md diff --git a/.changeset/grumpy-bottles-relate.md b/.changeset/grumpy-bottles-relate.md new file mode 100644 index 0000000000..aa1ecf0629 --- /dev/null +++ b/.changeset/grumpy-bottles-relate.md @@ -0,0 +1,7 @@ +--- +"@lens-protocol/react": patch +"@lens-protocol/react-native": patch +"@lens-protocol/react-web": patch +--- + +**fix:** refresh profile following after a follow or unfollow diff --git a/packages/react/src/shared.tsx b/packages/react/src/shared.tsx index 796fb749ff..26c41f61b2 100644 --- a/packages/react/src/shared.tsx +++ b/packages/react/src/shared.tsx @@ -115,11 +115,14 @@ export function createSharedDependencies(userConfig: BaseConfig): SharedDependen [TransactionKind.CREATE_POST]: new RefreshCurrentProfileResponder(profileCacheManager), [TransactionKind.CREATE_PROFILE]: new CreateProfileResponder(apolloClient), [TransactionKind.CREATE_QUOTE]: new RefreshCurrentProfileResponder(profileCacheManager), - [TransactionKind.FOLLOW_PROFILE]: new FollowProfileResponder(profileCacheManager), + [TransactionKind.FOLLOW_PROFILE]: new FollowProfileResponder(apolloClient, profileCacheManager), [TransactionKind.LINK_HANDLE]: new LinkHandleResponder(apolloClient, profileCacheManager), [TransactionKind.MIRROR_PUBLICATION]: new RefreshCurrentProfileResponder(profileCacheManager), [TransactionKind.UNBLOCK_PROFILE]: new UnblockProfilesResponder(profileCacheManager), - [TransactionKind.UNFOLLOW_PROFILE]: new UnfollowProfileResponder(profileCacheManager), + [TransactionKind.UNFOLLOW_PROFILE]: new UnfollowProfileResponder( + apolloClient, + profileCacheManager, + ), [TransactionKind.UNLINK_HANDLE]: new LinkHandleResponder(apolloClient, profileCacheManager), [TransactionKind.UPDATE_FOLLOW_POLICY]: new RefreshCurrentProfileResponder(profileCacheManager), [TransactionKind.UPDATE_PROFILE_DETAILS]: new RefreshCurrentProfileResponder( diff --git a/packages/react/src/transactions/adapters/responders/FollowProfileResponder.ts b/packages/react/src/transactions/adapters/responders/FollowProfileResponder.ts index 9e6d5174e9..d2e3e022eb 100644 --- a/packages/react/src/transactions/adapters/responders/FollowProfileResponder.ts +++ b/packages/react/src/transactions/adapters/responders/FollowProfileResponder.ts @@ -1,3 +1,4 @@ +import { FollowingDocument, SafeApolloClient } from '@lens-protocol/api-bindings'; import { FollowRequest } from '@lens-protocol/domain/use-cases/profile'; import { ITransactionResponder, @@ -7,9 +8,17 @@ import { import { IProfileCacheManager } from '../../../profile/adapters/IProfileCacheManager'; export class FollowProfileResponder implements ITransactionResponder { - constructor(private readonly profileCacheManager: IProfileCacheManager) {} + constructor( + private readonly apolloClient: SafeApolloClient, + private readonly profileCacheManager: IProfileCacheManager, + ) {} async commit({ request }: TransactionData) { - await this.profileCacheManager.fetchProfileById(request.profileId); + await Promise.all([ + this.profileCacheManager.fetchProfileById(request.profileId), + this.apolloClient.refetchQueries({ + include: [FollowingDocument], + }), + ]); } } diff --git a/packages/react/src/transactions/adapters/responders/UnfollowProfileResponder.ts b/packages/react/src/transactions/adapters/responders/UnfollowProfileResponder.ts index 88e248acab..f703a412f2 100644 --- a/packages/react/src/transactions/adapters/responders/UnfollowProfileResponder.ts +++ b/packages/react/src/transactions/adapters/responders/UnfollowProfileResponder.ts @@ -1,3 +1,4 @@ +import { FollowingDocument, SafeApolloClient } from '@lens-protocol/api-bindings'; import { UnfollowRequest } from '@lens-protocol/domain/use-cases/profile'; import { TransactionData, @@ -7,9 +8,17 @@ import { import { IProfileCacheManager } from '../../../profile/adapters/IProfileCacheManager'; export class UnfollowProfileResponder implements ITransactionResponder { - constructor(private readonly profileCacheManager: IProfileCacheManager) {} + constructor( + private readonly apolloClient: SafeApolloClient, + private readonly profileCacheManager: IProfileCacheManager, + ) {} async commit({ request }: TransactionData) { - await this.profileCacheManager.fetchProfileById(request.profileId); + await Promise.all([ + this.profileCacheManager.fetchProfileById(request.profileId), + this.apolloClient.refetchQueries({ + include: [FollowingDocument], + }), + ]); } }