From f0cd921109e09c8332e8ec7f5c16419e45e143ce Mon Sep 17 00:00:00 2001 From: mkljczk Date: Thu, 13 Mar 2025 12:40:21 +0100 Subject: [PATCH] pl-fe: update relationship on accepting/rejecting follow request Signed-off-by: mkljczk --- .../src/queries/accounts/use-follow-requests.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/pl-fe/src/queries/accounts/use-follow-requests.ts b/packages/pl-fe/src/queries/accounts/use-follow-requests.ts index a1fd1bc60..7e703469a 100644 --- a/packages/pl-fe/src/queries/accounts/use-follow-requests.ts +++ b/packages/pl-fe/src/queries/accounts/use-follow-requests.ts @@ -1,5 +1,7 @@ import { useMutation, type InfiniteData } from '@tanstack/react-query'; +import { importEntities } from 'pl-fe/actions/importer'; +import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch'; import { useClient } from 'pl-fe/hooks/use-client'; import { queryClient } from 'pl-fe/queries/client'; import { makePaginatedResponseQuery } from 'pl-fe/queries/utils/make-paginated-response-query'; @@ -35,21 +37,29 @@ const useFollowRequestsCount = makeUseFollowRequests((data) => data.pages.map(pa const useAcceptFollowRequestMutation = (accountId: string) => { const client = useClient(); + const dispatch = useAppDispatch(); return useMutation({ mutationKey: ['accountsLists', 'followRequests', accountId], mutationFn: () => client.myAccount.acceptFollowRequest(accountId), - onSettled: () => removeFollowRequest(accountId), + onSettled: ((relationship) => { + removeFollowRequest(accountId); + dispatch(importEntities({ relationships: [relationship] })); + }), }); }; const useRejectFollowRequestMutation = (accountId: string) => { const client = useClient(); + const dispatch = useAppDispatch(); return useMutation({ mutationKey: ['accountsLists', 'followRequests', accountId], mutationFn: () => client.myAccount.rejectFollowRequest(accountId), - onSettled: () => removeFollowRequest(accountId), + onSettled: ((relationship) => { + removeFollowRequest(accountId); + dispatch(importEntities({ relationships: [relationship] })); + }), }); };