Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD-460-Display-delete-post #207

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function AddCommentInput({
postFeedHomeStyle,
postId,
loggedInUser,
setCommentCounterIncrementLocal,
commentCounterIncrementLocal
}) {
const [focusInputComment, setFocusInputComment] = useState();
const [blurInputComment, setBlurInputComment] = useState();
Expand All @@ -27,7 +29,6 @@ function AddCommentInput({
const feedPostCollectionRef = collection(db, "feed_post");
const handleSubmitComments = async (e) => {
e.preventDefault();

if (!loggedInUser && !commentText){
return;
}
Expand All @@ -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);
}
Expand Down
71 changes: 57 additions & 14 deletions client/src/Components/PostsComponents/DropDownMenu/DropDownMenu.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<>
<section
Expand All @@ -46,12 +76,25 @@ function DropDownMenu({
}
>
<ul id={id}>
{/* {postCreatorId == loggedInUserId && ( */}
<>
<li>Supprimer</li>
<div className="separation-line-dropdown-menu"></div>
</>
{/* )} */}
{isPostsCommentsDisplay ? (
<>
{userId === loggedInUserId && (
<>
<li onClick={handleDeleteComments}>Supprimer</li>
<div className="separation-line-dropdown-menu"></div>
</>
)}
</>
) : (
<>
{postCreatorId === loggedInUserId && (
<>
<li onClick={handleDeletePosts}>Supprimer</li>
<div className="separation-line-dropdown-menu"></div>
</>
)}
</>
)}
{isPostsCommentsDisplay ? (
<>
<li onClick={() => handleClickCopyPostLink(userId, userType)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function HeadOfPost({
loggedInUserId,
isFullPagePostModalDisplay,
fullPagePostModalStyle,
userType,
}) {
// const [isPostTypePremium, setIsPostTypePremium] = useState([
// postType
Expand Down Expand Up @@ -124,6 +125,8 @@ function HeadOfPost({
addSuffix: true,
});
postDate = postDate.replace("environ ", "");
// console.log("postCreatorId --> ",postCreatorId)
// console.log("loggedInUserId --> ",loggedInUserId)
return (
<div
className={
Expand Down Expand Up @@ -215,6 +218,7 @@ function HeadOfPost({
fullPagePostPageStyle={fullPagePostPageStyle}
dropDownStatesFullPagePostModal={dropDownStatesFullPagePostModal}
fullPagePostModalStyle={fullPagePostModalStyle} // à voir si ça créer des conflits de css
userType={userType}
/>
</>
)}
Expand All @@ -228,6 +232,7 @@ function HeadOfPost({
fullPagePostPageStyle={fullPagePostPageStyle}
dropDownStatesFullPagePostModal={dropDownStatesFullPagePostModal}
fullPagePostModalStyle={fullPagePostModalStyle}
userType={userType}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function LikesCommentsCounter({
isMediaQueriesFullPagePostDisabled,
fullPagePostModalStyle,
fullPagePostPageStyle,
commentCounterIncrementLocal
}) {
const [pluralLikes, setPluralLikes] = useState();
useEffect(() => {
Expand All @@ -32,6 +33,7 @@ function LikesCommentsCounter({
}
}, []);

// postLikes + commentCounterIncrementLocal
return (
<div
className={
Expand Down Expand Up @@ -115,7 +117,7 @@ function LikesCommentsCounter({
}
>
<Link onClick={setIsPostClicked}>
{postCommentNumber} comments
{postCommentNumber + commentCounterIncrementLocal} comments
</Link>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function PostsComments({
handleClickCopyPostLink={handleClickCopyPostLink}
postCreatorId={postCreatorId}
loggedInUserId={loggedInUserId}
postId={postId}
/>
</>
)}
Expand Down
27 changes: 21 additions & 6 deletions client/src/Components/PostsComponents/PostsFeed/PostsFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ function PostsFeed({
polldata,
// singlePostData,
postFeedHomeStyle,
userType,
setCommentCounterIncrementLocal,
commentCounterIncrementLocal,
}) {
const [isPostClicked, setIsPostClicked] = useState(false);
const [isModdleToggled, setIsModalToggled] = useState(false);
const [commentsLengthPostsFeed, setCommentLengthPostsFeed] = useState();
// const [commentCounterIncrementLocal, setCommentCounterIncrementLocal] =
// useState(0);
function handleClickShowComment(e) {
e.preventDefault();
setIsPostClicked(true);
Expand Down Expand Up @@ -82,9 +87,6 @@ function PostsFeed({
);
}
}
// console.log("id de postfeed --> ",id)
// console.log(postCommentNumber);
console.log(postPicture);
return (
<>
<div
Expand Down Expand Up @@ -125,6 +127,8 @@ function PostsFeed({
//
handleDropdownPostFeedClick={handleDropdownPostFeedClick}
handleClickCopyPostLink={handleClickCopyPostLink}
loggedInUserId={loggedInUser?.id}
userType={userType}
/>
</div>
<PostsDescription
Expand All @@ -151,12 +155,18 @@ function PostsFeed({
postCommentNumber={postCommentNumber}
postId={id}
loggedInUserId={loggedInUser?.id}
commentCounterIncrementLocal={commentCounterIncrementLocal}
/>
<div className="show-comments-button-publication">
<Link onClick={(e) => handleClickShowComment(e)}>
Voir{postCommentNumber > 1 ? " les" : ""}{" "}
{postCommentNumber > 1
? postCommentNumber + " commentaires"
Voir
{postCommentNumber + commentCounterIncrementLocal > 1
? " les"
: ""}{" "}
{postCommentNumber + commentCounterIncrementLocal > 1
? postCommentNumber +
commentCounterIncrementLocal +
" commentaires"
: "commentaire(s)"}
</Link>
</div>
Expand All @@ -173,6 +183,8 @@ function PostsFeed({
postFeedHomeStyle={postFeedHomeStyle}
loggedInUser={loggedInUser}
postId={id}
setCommentCounterIncrementLocal={setCommentCounterIncrementLocal}
commentCounterIncrementLocal={commentCounterIncrementLocal}
/>
</div>
</div>
Expand Down Expand Up @@ -210,6 +222,9 @@ function PostsFeed({
isFullPagePostModalDisplay={true}
fullPagePostModalStyle={true}
setCommentLengthPostsFeed={setCommentLengthPostsFeed}
userType={userType}
commentCounterIncrementLocal={commentCounterIncrementLocal}

// postType={singlePostData.postType === "normal"}
/>
</Modal>
Expand Down
24 changes: 20 additions & 4 deletions client/src/Pages/FullPagePost/FullPagePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import PollPost from "../../Components/PostsComponents/PollPost/PollPost";
import DropDownMenu from "../../Components/PostsComponents/DropDownMenu/DropDownMenu";
import { v4 as uuidv4 } from "uuid";
import { db } from "../../Configs/firebase";
import { collection, query, orderBy, onSnapshot } from "firebase/firestore";
import {
collection,
query,
orderBy,
onSnapshot,
where,
} from "firebase/firestore";

function FullPagePost({
id,
Expand Down Expand Up @@ -39,6 +45,8 @@ function FullPagePost({
fullPagePostModalStyle,
loggedInUser,
setCommentLengthPostsFeed,
userType,
commentCounterIncrementLocal,
}) {
const [
isMediaQueriesFullPagePostDisabled,
Expand All @@ -65,7 +73,11 @@ function FullPagePost({

useEffect(() => {
const commentsRef = collection(db, `feed_post/${id}/post_comments`);
const q = query(commentsRef, orderBy("createdAt", "desc"));
const q = query(
commentsRef,
where("status", "==", true)
// orderBy("createdAt", "desc")
);

const unsubscribe = onSnapshot(q, (querySnapshot) => {
const comments = [];
Expand All @@ -74,8 +86,10 @@ function FullPagePost({
commentData.commentId = doc.id;
comments.push(commentData);
});
comments.sort((a, b) => b.createdAt.seconds - a.createdAt.seconds);
setComments(comments);
});
setCommentLengthPostsFeed(comments.length);

return () => {
unsubscribe();
Expand Down Expand Up @@ -118,7 +132,7 @@ function FullPagePost({
function handleDropdownPostFeedClick() {
// console.log("je m'appelle rami");
}
setCommentLengthPostsFeed(comments.length);
// setCommentLengthPostsFeed(comments.length);
function handleClickCopyPostLink(userId, userType) {
userType === "athlete"
? navigator.clipboard.writeText(
Expand All @@ -128,7 +142,6 @@ function FullPagePost({
`https://staging.sofan.app/userprofile/${userId}`
);
}
// console.log(comments)
return (
<>
<div
Expand Down Expand Up @@ -221,6 +234,7 @@ function FullPagePost({
handleClickCopyPostLink={handleClickCopyPostLink}
isFullPagePostModalDisplay={isFullPagePostModalDisplay}
fullPagePostModalStyle={fullPagePostModalStyle}
userType={userType}
/>
</div>
<PostsDescription
Expand Down Expand Up @@ -253,6 +267,7 @@ function FullPagePost({
}
fullPagePostModalStyle={fullPagePostModalStyle}
fullPagePostPageStyle={fullPagePostPageStyle}
commentCounterIncrementLocal={commentCounterIncrementLocal}
/>
</div>
<div
Expand Down Expand Up @@ -296,6 +311,7 @@ function FullPagePost({
isMediaQueriesFullPagePostDisabled
}
handleClickCopyPostLink={handleClickCopyPostLink}
postId={id}
/>
</>
);
Expand Down
Loading
Loading