Skip to content

Commit

Permalink
🚸feat(page): stop show post from reloading after state change
Browse files Browse the repository at this point in the history
  • Loading branch information
momcilovicluka committed Oct 28, 2024
1 parent c59f47d commit dfc1dc7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions resources/js/Pages/Post/ShowPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import PostActions from '@/Pages/Post/PostActions';
import PostDetails from '@/Pages/Post/PostDetails';
import CommentForm from '@/Pages/Comment/CommentForm';
import CommentItem from '@/Pages/Comment/CommentItem';
import { Inertia } from '@inertiajs/inertia';
import Footer from '@/Pages/Common/Footer';

export default function ShowPost({ auth, post }) {
Expand All @@ -21,14 +20,11 @@ export default function ShowPost({ auth, post }) {

const handleDeleteComment = (commentId) => {
if (confirm('Are you sure you want to delete this comment?')) {
Inertia.delete(route('comments.destroy', commentId), {
destroy(route('comments.destroy', commentId), {
preserveScroll: true,
onSuccess: () => {
console.log('Comment deleted successfully.');
},
onError: () => {
console.error('Failed to delete the comment.');
},
onError: (errors) => {
window.alert('Error deleting comment:', errors);
}
});
}
};
Expand All @@ -40,11 +36,12 @@ export default function ShowPost({ auth, post }) {
const handleCommentSubmit = (e) => {
e.preventDefault();
submitComment(route('comments.store', post.id), {
preserveScroll: true,
onSuccess: () => {
setData({ comment: '' });
},
onError: (errors) => {
console.error('Error adding comment:', errors);
window.alert('Error adding comment:', errors);
}
});
};
Expand Down

0 comments on commit dfc1dc7

Please sign in to comment.