pl-fe: no point in using useEntities here

Signed-off-by: Nicole Mikołajczyk <git@mkljczk.pl>
This commit is contained in:
Nicole Mikołajczyk
2025-05-05 11:51:19 +02:00
parent 0ae92e4e55
commit 7f47d95767
4 changed files with 11 additions and 34 deletions

View File

@ -125,7 +125,7 @@ describe('deleteStatus()', () => {
{ type: 'MODAL_CLOSE', modalType: 'COMPOSE', modalProps: undefined },
{ type: 'MODAL_OPEN', modalType: 'COMPOSE', modalProps: undefined },
];
await store.dispatch(deleteStatus(statusId, true));
await store.dispatch(deleteStatus(statusId, undefined, true));
const actions = store.getActions();
expect(actions).toEqual(expectedActions);
@ -151,7 +151,7 @@ describe('deleteStatus()', () => {
error: new Error('Network Error'),
},
];
await store.dispatch(deleteStatus(statusId, true));
await store.dispatch(deleteStatus(statusId, undefined, true));
const actions = store.getActions();
expect(actions).toEqual(expectedActions);

View File

@ -108,7 +108,7 @@ const fetchStatus = (statusId: string, intl?: IntlShape) =>
});
};
const deleteStatus = (statusId: string, withRedraft = false) =>
const deleteStatus = (statusId: string, groupId?: string, withRedraft = false) =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return null;
@ -119,7 +119,11 @@ const deleteStatus = (statusId: string, withRedraft = false) =>
dispatch<StatusesAction>({ type: STATUS_DELETE_REQUEST, params: status });
return getClient(state).statuses.deleteStatus(statusId).then(response => {
return (
groupId
? getClient(state).experimental.groups.deleteGroupStatus(statusId, groupId)
: getClient(state).statuses.deleteStatus(statusId)
).then(response => {
dispatch<StatusesAction>({ type: STATUS_DELETE_SUCCESS, statusId });
dispatch(deleteFromTimelines(statusId));

View File

@ -1,20 +0,0 @@
import { Entities } from 'pl-fe/entity-store/entities';
import { useDeleteEntity } from 'pl-fe/entity-store/hooks/use-delete-entity';
import { useClient } from 'pl-fe/hooks/use-client';
import type { Group } from 'pl-api';
const useDeleteGroupStatus = (group: Pick<Group, 'id'>, statusId: string) => {
const client = useClient();
const { deleteEntity, isSubmitting } = useDeleteEntity(
Entities.STATUSES,
() => client.experimental.groups.deleteGroupStatus(group.id, statusId),
);
return {
mutate: deleteEntity,
isSubmitting,
};
};
export { useDeleteGroupStatus };

View File

@ -11,8 +11,6 @@ import { deleteStatusModal, toggleStatusSensitivityModal } from 'pl-fe/actions/m
import { initReport, ReportableEntities } from 'pl-fe/actions/reports';
import { changeSetting } from 'pl-fe/actions/settings';
import { deleteStatus, editStatus, toggleMuteStatus } from 'pl-fe/actions/statuses';
import { deleteFromTimelines } from 'pl-fe/actions/timelines';
import { useDeleteGroupStatus } from 'pl-fe/api/hooks/groups/use-delete-group-status';
import { useGroup } from 'pl-fe/api/hooks/groups/use-group';
import { useGroupRelationship } from 'pl-fe/api/hooks/groups/use-group-relationship';
import DropdownMenu from 'pl-fe/components/dropdown-menu';
@ -596,7 +594,6 @@ const MenuButton: React.FC<IMenuButton> = ({
const targetLanguage = statusesMeta[status.id]?.targetLanguage;
const { openModal } = useModalsStore();
const { group } = useGroup((status.group as Group)?.id as string);
const deleteGroupStatus = useDeleteGroupStatus(group as Group, status.id);
const { mutate: blockGroupMember } = useBlockGroupUserMutation(status.group?.id as string, status.account.id);
const { getOrCreateChatByAccountId } = useChats();
@ -640,13 +637,13 @@ const MenuButton: React.FC<IMenuButton> = ({
const doDeleteStatus = (withRedraft = false) => {
if (!deleteModal) {
dispatch(deleteStatus(status.id, withRedraft));
dispatch(deleteStatus(status.id, undefined, withRedraft));
} else {
openModal('CONFIRM', {
heading: intl.formatMessage(withRedraft ? messages.redraftHeading : messages.deleteHeading),
message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
onConfirm: () => dispatch(deleteStatus(status.id, withRedraft)),
onConfirm: () => dispatch(deleteStatus(status.id, undefined, withRedraft)),
});
}
};
@ -765,11 +762,7 @@ const MenuButton: React.FC<IMenuButton> = ({
message: intl.formatMessage(messages.deleteFromGroupMessage, { name: <strong className='break-words'>{account.username}</strong> }),
confirm: intl.formatMessage(messages.deleteConfirm),
onConfirm: () => {
deleteGroupStatus.mutate(status.id, {
onSuccess() {
dispatch(deleteFromTimelines(status.id));
},
});
dispatch(deleteStatus(status.id, group?.id));
},
});
};