-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.jsx
66 lines (61 loc) · 2.24 KB
/
comment.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { useState } from "react";
import "./Comments.scss";
import CommentStructure from "./commentStructure";
const Comment = (props) => {
const [showReplies, setShowReplies] = useState(false);
const ShowReplies = () => setShowReplies(true);
const Hidereplies = () => setShowReplies(false);
// it will not show the replies initially you can see replies by clicking on View Replies
return (
<div className="CM-Wrapper">
{/* this the parent comment */}
<CommentStructure
commentId={props.commentId}
CurrentUser={props.CurrentUser}
username={props.username}
text={props.text}
likes={props.likes}
avatar={props.avatar}
showLikes={(likes) => props.showLikes(likes)}
handleHeart={(ParentCmtID, ReplyCmtID, ChangeHeart) =>
props.handleHeart(ParentCmtID, ReplyCmtID, ChangeHeart)
}
handleReply={(cmtID) => props.handleReply(cmtID)}
/>
<div className="reply-container">
{!showReplies && props.replies.length > 0 ? (
<p className="view-replies" onClick={ShowReplies}>
View Replies
</p>
) : null}
{showReplies
? props.replies.map((reply, index) => {
// all the replies of this comment is rendered here
return (
<CommentStructure
thisReplyCommentId={reply.commentId}
commentId={props.commentId}
CurrentUser={props.CurrentUser}
username={reply.username}
text={reply.comment}
likes={reply.likes}
avatar={reply.avatar}
showLikes={(likes) => props.showLikes(likes)}
handleHeart={(ParentCmtID, ReplyCmtID, ChangeHeart) =>
props.handleHeart(ParentCmtID, ReplyCmtID, ChangeHeart)
}
handleReply={(cmtID) => props.handleReply(cmtID)}
/>
);
})
: null}
{showReplies && props.replies.length > 0 ? (
<p className="hide-replies" onClick={Hidereplies}>
Hide Replies
</p>
) : null}
</div>
</div>
);
};
export default React.memo(Comment);