[Glitch] Fix 404 error after deleting status from detail view

Port d93572ea90e7b61aa570c7223f0a69561dbbff61 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Kazuki Nagasawa 2025-08-29 05:50:19 +09:00 committed by Claire
parent 6abe6cdef5
commit bf3c53661a
4 changed files with 54 additions and 8 deletions

View File

@ -1,7 +1,10 @@
import { defineMessages } from 'react-intl';
import { browserHistory } from 'flavours/glitch/components/router'; import { browserHistory } from 'flavours/glitch/components/router';
import api from '../api'; import api from '../api';
import { showAlert } from './alerts';
import { ensureComposeIsVisible, setComposeToStatus } from './compose'; import { ensureComposeIsVisible, setComposeToStatus } from './compose';
import { importFetchedStatus, importFetchedAccount } from './importer'; import { importFetchedStatus, importFetchedAccount } from './importer';
import { fetchContext } from './statuses_typed'; 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_FAIL = 'STATUS_TRANSLATE_FAIL';
export const STATUS_TRANSLATE_UNDO = 'STATUS_TRANSLATE_UNDO'; export const STATUS_TRANSLATE_UNDO = 'STATUS_TRANSLATE_UNDO';
const messages = defineMessages({
deleteSuccess: { id: 'status.delete.success', defaultMessage: 'Post deleted' },
});
export function fetchStatusRequest(id, skipLoading) { export function fetchStatusRequest(id, skipLoading) {
return { return {
type: STATUS_FETCH_REQUEST, type: STATUS_FETCH_REQUEST,
@ -155,7 +162,7 @@ export function deleteStatus(id, withRedraft = false) {
dispatch(deleteStatusRequest(id)); 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(deleteStatusSuccess(id));
dispatch(deleteFromTimelines(id)); dispatch(deleteFromTimelines(id));
dispatch(importFetchedAccount(response.data.account)); dispatch(importFetchedAccount(response.data.account));
@ -163,9 +170,14 @@ export function deleteStatus(id, withRedraft = false) {
if (withRedraft) { if (withRedraft) {
dispatch(redraft(status, response.data.text, response.data.content_type)); dispatch(redraft(status, response.data.text, response.data.content_type));
ensureComposeIsVisible(getState); ensureComposeIsVisible(getState);
} else {
dispatch(showAlert({ message: messages.deleteSuccess }));
} }
return response;
}).catch(error => { }).catch(error => {
dispatch(deleteStatusFail(id, error)); dispatch(deleteStatusFail(id, error));
throw error;
}); });
}; };
} }

View File

@ -125,7 +125,13 @@ const mapDispatchToProps = (dispatch, { contextType }) => ({
if (!deleteModal) { if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), withRedraft)); dispatch(deleteStatus(status.get('id'), withRedraft));
} else { } 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
}
}));
} }
}, },

View File

@ -281,12 +281,31 @@ class Status extends ImmutablePureComponent {
}; };
handleDeleteClick = (status, withRedraft = false) => { handleDeleteClick = (status, withRedraft = false) => {
const { dispatch } = this.props; const { dispatch, history } = this.props;
const handleDeleteSuccess = () => {
history.push('/');
};
if (!deleteModal) { 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 { } 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
}
}));
} }
}; };

View File

@ -40,14 +40,23 @@ export const ConfirmDeleteStatusModal: React.FC<
{ {
statusId: string; statusId: string;
withRedraft: boolean; withRedraft: boolean;
onDeleteSuccess?: () => void;
} & BaseConfirmationModalProps } & BaseConfirmationModalProps
> = ({ statusId, withRedraft, onClose }) => { > = ({ statusId, withRedraft, onClose, onDeleteSuccess }) => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const onConfirm = useCallback(() => { const onConfirm = useCallback(() => {
dispatch(deleteStatus(statusId, withRedraft)); void dispatch(deleteStatus(statusId, withRedraft))
}, [dispatch, statusId, withRedraft]); .then(() => {
onDeleteSuccess?.();
onClose();
})
.catch(() => {
// Error handling - still close modal
onClose();
});
}, [dispatch, statusId, withRedraft, onDeleteSuccess, onClose]);
return ( return (
<ConfirmationModal <ConfirmationModal