mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
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:
@@ -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;
|
||||
Reference in New Issue
Block a user