Skip to content

Commit

Permalink
only comment owners can delete them
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandyrzph committed Aug 3, 2022
1 parent 6de9822 commit b945d0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 8 additions & 6 deletions pixelplace/src/components/Comment/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ToastContainer } from "react-toastify";
import { toastError } from "../../utils/Toast";
import { HiX } from "react-icons/hi";

const Comment = ({ photoURL, displayName, comment, commentId, uid, postId }) => {
const Comment = ({ photoURL, displayName, comment, commentId, uid, currentUserId, postId }) => {
const deleteCommentHandler = (e) => {
deleteDoc(doc(db, "Posts", postId, "comments", commentId))
.then()
Expand All @@ -23,11 +23,13 @@ const Comment = ({ photoURL, displayName, comment, commentId, uid, postId }) =>
<p className="w-full font-bold">@{displayName}</p>
<p className="w-full">{comment}</p>
</div>
<HiX
cursor={"pointer"}
onClick={deleteCommentHandler}
className="hover:bg-slate-300 text-lg text-gray-500 hover:text-black rounded-full duration-100"
/>
{currentUserId == uid ? (
<HiX
cursor={"pointer"}
onClick={deleteCommentHandler}
className="hover:bg-slate-300 text-lg text-gray-500 hover:text-black rounded-full duration-100"
/>
) : null}
</div>
);
};
Expand Down
7 changes: 6 additions & 1 deletion pixelplace/src/components/PostDetails/PostDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ const PostDetails = () => {
<p>No comments yet</p>
) : (
comments.map((comment) => (
<Comment {...comment} key={uuidv4()} postId={postId} />
<Comment
{...comment}
key={uuidv4()}
postId={postId}
currentUserId={user.uid}
/>
))
)}
</div>
Expand Down

0 comments on commit b945d0a

Please sign in to comment.