pl-fe: improve side effects

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2024-12-05 11:02:14 +01:00
parent 42e857db76
commit c11ed8a6ac
2 changed files with 9 additions and 4 deletions

View File

@ -1,9 +1,11 @@
import { useMutation, type InfiniteData } from '@tanstack/react-query';
import { makePaginatedResponseQuery } from 'pl-fe/queries/utils/make-paginated-response-query';
import { minifyAccountList } from 'pl-fe/queries/utils/minify-list';
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';
import { minifyAccountList } from 'pl-fe/queries/utils/minify-list';
import { removeGroupMember } from './use-group-members';
const appendGroupBlock = (groupId: string, accountId: string) =>
queryClient.setQueryData<InfiniteData<ReturnType<typeof minifyAccountList>>>(['accountsLists', 'groupBlocks', groupId], (data) => {
@ -32,7 +34,10 @@ const useBlockGroupUserMutation = (groupId: string, accountId: string) => {
return useMutation({
mutationKey: ['accountsLists', 'groupBlocks', groupId, accountId],
mutationFn: () => client.experimental.groups.blockGroupUsers(groupId, [accountId]),
onSettled: () => appendGroupBlock(groupId, accountId),
onSettled: () => {
removeGroupMember(groupId, accountId);
appendGroupBlock(groupId, accountId);
},
});
};

View File

@ -42,4 +42,4 @@ const useKickGroupMemberMutation = (groupId: string, accountId: string) => {
type MinifiedGroupMember = ReturnType<typeof minifyGroupMembersList>['items'][0];
export { useGroupMembers, useKickGroupMemberMutation, type MinifiedGroupMember };
export { useGroupMembers, useKickGroupMemberMutation, removeGroupMember, type MinifiedGroupMember };