From 7f47d957679aea23b26ca2db7a81a258479ebd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicole=20Miko=C5=82ajczyk?= Date: Mon, 5 May 2025 11:51:19 +0200 Subject: [PATCH] pl-fe: no point in using useEntities here MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicole Mikołajczyk --- packages/pl-fe/src/actions/statuses.test.ts | 4 ++-- packages/pl-fe/src/actions/statuses.ts | 8 ++++++-- .../hooks/groups/use-delete-group-status.ts | 20 ------------------- .../src/components/status-action-bar.tsx | 13 +++--------- 4 files changed, 11 insertions(+), 34 deletions(-) delete mode 100644 packages/pl-fe/src/api/hooks/groups/use-delete-group-status.ts diff --git a/packages/pl-fe/src/actions/statuses.test.ts b/packages/pl-fe/src/actions/statuses.test.ts index c2158a76a..a9575d8a1 100644 --- a/packages/pl-fe/src/actions/statuses.test.ts +++ b/packages/pl-fe/src/actions/statuses.test.ts @@ -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); diff --git a/packages/pl-fe/src/actions/statuses.ts b/packages/pl-fe/src/actions/statuses.ts index c38e7824e..57d9aa5f3 100644 --- a/packages/pl-fe/src/actions/statuses.ts +++ b/packages/pl-fe/src/actions/statuses.ts @@ -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({ 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({ type: STATUS_DELETE_SUCCESS, statusId }); dispatch(deleteFromTimelines(statusId)); diff --git a/packages/pl-fe/src/api/hooks/groups/use-delete-group-status.ts b/packages/pl-fe/src/api/hooks/groups/use-delete-group-status.ts deleted file mode 100644 index f2a08bd13..000000000 --- a/packages/pl-fe/src/api/hooks/groups/use-delete-group-status.ts +++ /dev/null @@ -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, statusId: string) => { - const client = useClient(); - const { deleteEntity, isSubmitting } = useDeleteEntity( - Entities.STATUSES, - () => client.experimental.groups.deleteGroupStatus(group.id, statusId), - ); - - return { - mutate: deleteEntity, - isSubmitting, - }; -}; - -export { useDeleteGroupStatus }; diff --git a/packages/pl-fe/src/components/status-action-bar.tsx b/packages/pl-fe/src/components/status-action-bar.tsx index 807dab142..d4297e607 100644 --- a/packages/pl-fe/src/components/status-action-bar.tsx +++ b/packages/pl-fe/src/components/status-action-bar.tsx @@ -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 = ({ 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 = ({ 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 = ({ message: intl.formatMessage(messages.deleteFromGroupMessage, { name: {account.username} }), confirm: intl.formatMessage(messages.deleteConfirm), onConfirm: () => { - deleteGroupStatus.mutate(status.id, { - onSuccess() { - dispatch(deleteFromTimelines(status.id)); - }, - }); + dispatch(deleteStatus(status.id, group?.id)); }, }); };