pl-fe: update relationship on accepting/rejecting follow request

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2025-03-13 12:40:21 +01:00
parent 798956fa5a
commit f0cd921109

View File

@ -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] }));
}),
});
};