diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 3fddd1bcc5..7572efe95f 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -1,7 +1,10 @@ +import { defineMessages } from 'react-intl'; + import { browserHistory } from 'mastodon/components/router'; import api from '../api'; +import { showAlert } from './alerts'; import { ensureComposeIsVisible, setComposeToStatus } from './compose'; import { importFetchedStatus, importFetchedAccount } from './importer'; import { fetchContext } from './statuses_typed'; @@ -40,6 +43,10 @@ export const STATUS_TRANSLATE_SUCCESS = 'STATUS_TRANSLATE_SUCCESS'; export const STATUS_TRANSLATE_FAIL = 'STATUS_TRANSLATE_FAIL'; export const STATUS_TRANSLATE_UNDO = 'STATUS_TRANSLATE_UNDO'; +const messages = defineMessages({ + deleteSuccess: { id: 'status.delete.success', defaultMessage: 'Post deleted' }, +}); + export function fetchStatusRequest(id, skipLoading) { return { type: STATUS_FETCH_REQUEST, @@ -154,7 +161,7 @@ export function deleteStatus(id, withRedraft = false) { dispatch(deleteStatusRequest(id)); - api().delete(`/api/v1/statuses/${id}`, { params: { delete_media: !withRedraft } }).then(response => { + return api().delete(`/api/v1/statuses/${id}`, { params: { delete_media: !withRedraft } }).then(response => { dispatch(deleteStatusSuccess(id)); dispatch(deleteFromTimelines(id)); dispatch(importFetchedAccount(response.data.account)); @@ -162,9 +169,14 @@ export function deleteStatus(id, withRedraft = false) { if (withRedraft) { dispatch(redraft(status, response.data.text)); ensureComposeIsVisible(getState); + } else { + dispatch(showAlert({ message: messages.deleteSuccess })); } + + return response; }).catch(error => { dispatch(deleteStatusFail(id, error)); + throw error; }); }; } diff --git a/app/javascript/mastodon/containers/status_container.jsx b/app/javascript/mastodon/containers/status_container.jsx index f451db661c..e73ef5b96e 100644 --- a/app/javascript/mastodon/containers/status_container.jsx +++ b/app/javascript/mastodon/containers/status_container.jsx @@ -117,7 +117,13 @@ const mapDispatchToProps = (dispatch, { contextType }) => ({ if (!deleteModal) { dispatch(deleteStatus(status.get('id'), withRedraft)); } else { - dispatch(openModal({ modalType: 'CONFIRM_DELETE_STATUS', modalProps: { statusId: status.get('id'), withRedraft } })); + dispatch(openModal({ + modalType: 'CONFIRM_DELETE_STATUS', + modalProps: { + statusId: status.get('id'), + withRedraft + } + })); } }, diff --git a/app/javascript/mastodon/features/status/index.jsx b/app/javascript/mastodon/features/status/index.jsx index 3c197150e5..362ad2c5e2 100644 --- a/app/javascript/mastodon/features/status/index.jsx +++ b/app/javascript/mastodon/features/status/index.jsx @@ -251,12 +251,31 @@ class Status extends ImmutablePureComponent { }; handleDeleteClick = (status, withRedraft = false) => { - const { dispatch } = this.props; + const { dispatch, history } = this.props; + + const handleDeleteSuccess = () => { + history.push('/'); + }; if (!deleteModal) { - dispatch(deleteStatus(status.get('id'), withRedraft)); + dispatch(deleteStatus(status.get('id'), withRedraft)) + .then(() => { + if (!withRedraft) { + handleDeleteSuccess(); + } + }) + .catch(() => { + // Error handling - could show error message + }); } else { - dispatch(openModal({ modalType: 'CONFIRM_DELETE_STATUS', modalProps: { statusId: status.get('id'), withRedraft } })); + dispatch(openModal({ + modalType: 'CONFIRM_DELETE_STATUS', + modalProps: { + statusId: status.get('id'), + withRedraft, + onDeleteSuccess: handleDeleteSuccess + } + })); } }; diff --git a/app/javascript/mastodon/features/ui/components/confirmation_modals/delete_status.tsx b/app/javascript/mastodon/features/ui/components/confirmation_modals/delete_status.tsx index 39e80cf741..215ba31a46 100644 --- a/app/javascript/mastodon/features/ui/components/confirmation_modals/delete_status.tsx +++ b/app/javascript/mastodon/features/ui/components/confirmation_modals/delete_status.tsx @@ -40,14 +40,23 @@ export const ConfirmDeleteStatusModal: React.FC< { statusId: string; withRedraft: boolean; + onDeleteSuccess?: () => void; } & BaseConfirmationModalProps -> = ({ statusId, withRedraft, onClose }) => { +> = ({ statusId, withRedraft, onClose, onDeleteSuccess }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const onConfirm = useCallback(() => { - dispatch(deleteStatus(statusId, withRedraft)); - }, [dispatch, statusId, withRedraft]); + void dispatch(deleteStatus(statusId, withRedraft)) + .then(() => { + onDeleteSuccess?.(); + onClose(); + }) + .catch(() => { + // Error handling - still close modal + onClose(); + }); + }, [dispatch, statusId, withRedraft, onDeleteSuccess, onClose]); return (