From bf3c53661a9c708cfb3359464c0fc2e8c7c7e810 Mon Sep 17 00:00:00 2001 From: Kazuki Nagasawa <113568707+crafkaz@users.noreply.github.com> Date: Fri, 29 Aug 2025 05:50:19 +0900 Subject: [PATCH] [Glitch] Fix 404 error after deleting status from detail view Port d93572ea90e7b61aa570c7223f0a69561dbbff61 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/actions/statuses.js | 14 ++++++++++- .../glitch/containers/status_container.js | 8 +++++- .../flavours/glitch/features/status/index.jsx | 25 ++++++++++++++++--- .../confirmation_modals/delete_status.tsx | 15 ++++++++--- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/statuses.js b/app/javascript/flavours/glitch/actions/statuses.js index c405d785cc..bfb20dc401 100644 --- a/app/javascript/flavours/glitch/actions/statuses.js +++ b/app/javascript/flavours/glitch/actions/statuses.js @@ -1,7 +1,10 @@ +import { defineMessages } from 'react-intl'; + import { browserHistory } from 'flavours/glitch/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, @@ -155,7 +162,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)); @@ -163,9 +170,14 @@ export function deleteStatus(id, withRedraft = false) { if (withRedraft) { dispatch(redraft(status, response.data.text, response.data.content_type)); ensureComposeIsVisible(getState); + } else { + dispatch(showAlert({ message: messages.deleteSuccess })); } + + return response; }).catch(error => { dispatch(deleteStatusFail(id, error)); + throw error; }); }; } diff --git a/app/javascript/flavours/glitch/containers/status_container.js b/app/javascript/flavours/glitch/containers/status_container.js index e0965aa9ef..ca7b8b5529 100644 --- a/app/javascript/flavours/glitch/containers/status_container.js +++ b/app/javascript/flavours/glitch/containers/status_container.js @@ -125,7 +125,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/flavours/glitch/features/status/index.jsx b/app/javascript/flavours/glitch/features/status/index.jsx index fbd24bcf4a..0e3a1c193a 100644 --- a/app/javascript/flavours/glitch/features/status/index.jsx +++ b/app/javascript/flavours/glitch/features/status/index.jsx @@ -281,12 +281,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/flavours/glitch/features/ui/components/confirmation_modals/delete_status.tsx b/app/javascript/flavours/glitch/features/ui/components/confirmation_modals/delete_status.tsx index e86cec10c0..6dd439d4d0 100644 --- a/app/javascript/flavours/glitch/features/ui/components/confirmation_modals/delete_status.tsx +++ b/app/javascript/flavours/glitch/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 (