Skip to content

Commit b945d0a

Browse files
committed
only comment owners can delete them
1 parent 6de9822 commit b945d0a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pixelplace/src/components/Comment/Comment.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ToastContainer } from "react-toastify";
44
import { toastError } from "../../utils/Toast";
55
import { HiX } from "react-icons/hi";
66

7-
const Comment = ({ photoURL, displayName, comment, commentId, uid, postId }) => {
7+
const Comment = ({ photoURL, displayName, comment, commentId, uid, currentUserId, postId }) => {
88
const deleteCommentHandler = (e) => {
99
deleteDoc(doc(db, "Posts", postId, "comments", commentId))
1010
.then()
@@ -23,11 +23,13 @@ const Comment = ({ photoURL, displayName, comment, commentId, uid, postId }) =>
2323
<p className="w-full font-bold">@{displayName}</p>
2424
<p className="w-full">{comment}</p>
2525
</div>
26-
<HiX
27-
cursor={"pointer"}
28-
onClick={deleteCommentHandler}
29-
className="hover:bg-slate-300 text-lg text-gray-500 hover:text-black rounded-full duration-100"
30-
/>
26+
{currentUserId == uid ? (
27+
<HiX
28+
cursor={"pointer"}
29+
onClick={deleteCommentHandler}
30+
className="hover:bg-slate-300 text-lg text-gray-500 hover:text-black rounded-full duration-100"
31+
/>
32+
) : null}
3133
</div>
3234
);
3335
};

pixelplace/src/components/PostDetails/PostDetails.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ const PostDetails = () => {
146146
<p>No comments yet</p>
147147
) : (
148148
comments.map((comment) => (
149-
<Comment {...comment} key={uuidv4()} postId={postId} />
149+
<Comment
150+
{...comment}
151+
key={uuidv4()}
152+
postId={postId}
153+
currentUserId={user.uid}
154+
/>
150155
))
151156
)}
152157
</div>

0 commit comments

Comments
 (0)