Skip to content

Commit c59f47d

Browse files
✨feat(page): preserve scroll when deleting comment on show post
1 parent b4b868b commit c59f47d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

resources/js/Pages/Post/ShowPost.jsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PostActions from '@/Pages/Post/PostActions';
55
import PostDetails from '@/Pages/Post/PostDetails';
66
import CommentForm from '@/Pages/Comment/CommentForm';
77
import CommentItem from '@/Pages/Comment/CommentItem';
8+
import { Inertia } from '@inertiajs/inertia';
89
import Footer from '@/Pages/Common/Footer';
910

1011
export default function ShowPost({ auth, post }) {
@@ -20,13 +21,14 @@ export default function ShowPost({ auth, post }) {
2021

2122
const handleDeleteComment = (commentId) => {
2223
if (confirm('Are you sure you want to delete this comment?')) {
23-
destroy(route('comments.destroy', commentId), {
24+
Inertia.delete(route('comments.destroy', commentId), {
25+
preserveScroll: true,
2426
onSuccess: () => {
25-
console.log('Comment deleted successfully');
27+
console.log('Comment deleted successfully.');
28+
},
29+
onError: () => {
30+
console.error('Failed to delete the comment.');
2631
},
27-
onError: (errors) => {
28-
console.error('Error deleting comment:', errors);
29-
}
3032
});
3133
}
3234
};

0 commit comments

Comments
 (0)