diff --git a/.changeset/grumpy-bottles-relate.md b/.changeset/grumpy-bottles-relate.md new file mode 100644 index 000000000..aa1ecf062 --- /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 796fb749f..26c41f61b 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 9e6d5174e..d2e3e022e 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 88e248aca..f703a412f 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], + }), + ]); } }