From c6b1912dc87834218a43b47f67b5f59d548daa7a Mon Sep 17 00:00:00 2001 From: Ra Date: Thu, 7 Sep 2023 04:02:18 +0200 Subject: [PATCH] soft delete comment + soft delete post + counterIncrementLocaly for comment counter --- .../AddCommentInput/AddCommentInput.js | 6 +- .../DropDownMenu/DropDownMenu.js | 71 +++++++++++++++---- .../PostsComponents/HeadOfPost/HeadOfPost.js | 5 ++ .../LikesCommentsCounter.js | 4 +- .../PostsComments/PostsComments.js | 1 + .../PostsComponents/PostsFeed/PostsFeed.js | 27 +++++-- client/src/Pages/FullPagePost/FullPagePost.js | 24 +++++-- client/src/Pages/Home/Home.js | 20 ++++-- 8 files changed, 128 insertions(+), 30 deletions(-) diff --git a/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js b/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js index 9ab35b25..18bd5201 100644 --- a/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js +++ b/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js @@ -14,6 +14,8 @@ function AddCommentInput({ postFeedHomeStyle, postId, loggedInUser, + setCommentCounterIncrementLocal, + commentCounterIncrementLocal }) { const [focusInputComment, setFocusInputComment] = useState(); const [blurInputComment, setBlurInputComment] = useState(); @@ -27,7 +29,6 @@ function AddCommentInput({ const feedPostCollectionRef = collection(db, "feed_post"); const handleSubmitComments = async (e) => { e.preventDefault(); - if (!loggedInUser && !commentText){ return; } @@ -49,6 +50,9 @@ function AddCommentInput({ ); await addDoc(commentRef, commentData); console.log("Comment successfully added!"); + // state here + setCommentCounterIncrementLocal(prevState => prevState + 1); + console.log("compteur depis AddCommentInput --> ",commentCounterIncrementLocal) } catch (e) { console.error("Error adding comment: ", e); } diff --git a/client/src/Components/PostsComponents/DropDownMenu/DropDownMenu.js b/client/src/Components/PostsComponents/DropDownMenu/DropDownMenu.js index ae35423a..8d5ea545 100644 --- a/client/src/Components/PostsComponents/DropDownMenu/DropDownMenu.js +++ b/client/src/Components/PostsComponents/DropDownMenu/DropDownMenu.js @@ -1,6 +1,7 @@ -import React from "react"; +import React, { useEffect } from "react"; import "./DropDownMenu.css"; - +import { updateDoc, doc } from "firebase/firestore"; +import { db } from "../../../Configs/firebase"; function DropDownMenu({ dropdownStates, id, @@ -13,13 +14,42 @@ function DropDownMenu({ userType, userId, isPostsCommentsDisplay, + commentId, + postId, }) { - // Backend here - const isOwner = true; - // console.log(loggedInUserId); - console.log( - "", postCreatorId, - loggedInUserId) + async function handleDeleteComments(e) { + try { + // Créer une référence vers le commentaire que vous souhaitez supprimer + const commentRef = doc( + db, + `feed_post/${postId}/post_comments/${commentId}` + ); + + // Mettre à jour le champ 'status' en le mettant à false + await updateDoc(commentRef, { + status: false, + }); + + console.log("Le status a bien été passé à false"); + } catch (error) { + console.error("Erreur lors de la mise à jour du statut:", error); + } + } + async function handleDeletePosts(e) { + try { + // Créer une référence vers le commentaire que vous souhaitez supprimer + const postRef = doc(db, `feed_post/${id}`); + + // Mettre à jour le champ 'status' en le mettant à false + await updateDoc(postRef, { + status: false, + }); + + console.log("Le status a bien été passé à false"); + } catch (error) { + console.error("Erreur lors de la mise à jour du statut:", error); + } + } return ( <>