fix(post): move failed publish notice into comment body (#1066)

Align the failed notice and delete action with the existing post card and footer controls.
This commit is contained in:
Tommaso Casaburi
2026-03-12 17:56:52 +08:00
committed by GitHub
parent 053965f124
commit 0aafb7f538
7 changed files with 147 additions and 74 deletions
+38
View File
@@ -0,0 +1,38 @@
import { useCallback, useState } from 'react';
import { deleteComment } from '@bitsocialnet/bitsocial-react-hooks';
const useDeleteFailedPost = (post?: { cid?: string; index?: number; state?: string }) => {
const [isDeletingFailedPost, setIsDeletingFailedPost] = useState(false);
const canDeleteFailedPost = post?.state === 'failed' && typeof post?.index === 'number';
const onDeleteFailedPost = useCallback(() => {
if (isDeletingFailedPost || !canDeleteFailedPost) {
return;
}
const targetComment = post?.cid ?? post?.index;
if (typeof targetComment === 'undefined') {
return;
}
setIsDeletingFailedPost(true);
deleteComment(targetComment)
.then(() => {
setIsDeletingFailedPost(false);
})
.catch((error) => {
console.error('Failed to delete failed post:', error);
alert(`Failed to delete post: ${error instanceof Error ? error.message : 'Unknown error'}`);
setIsDeletingFailedPost(false);
});
}, [canDeleteFailedPost, isDeletingFailedPost, post?.cid, post?.index]);
return {
canDeleteFailedPost,
isDeletingFailedPost,
onDeleteFailedPost,
};
};
export default useDeleteFailedPost;