11import React , { useCallback } from "react" ;
22import * as S from "./styles" ;
3- import ViewMarkdown from "@components/ViewMarkdown" ;
4- import Heart from "@components/Icons/Heart" ;
5- import NewComment from "@components/NewComment" ;
3+
64import { list } from "./list" ;
5+ import Comment from "@components/Comment" ;
76
87const CommentsList : React . FC = ( ) => {
98 const currentUser = "Parlandim" ;
@@ -21,93 +20,28 @@ const CommentsList: React.FC = () => {
2120 [ replyComment ]
2221 ) ;
2322
24- const userMention = useCallback (
25- ( content : string ) => {
26- const newContent = content . replace (
27- `@${ currentUser } ` ,
28- `<span className="mention">@${ currentUser } </span>`
29- ) ;
30-
31- return newContent ;
32- } ,
33- [ currentUser ]
34- ) ;
35-
3623 return (
3724 < S . Container >
3825 { list . map ( ( item ) => (
39- < S . CommentContainer key = { item . id } >
40- < S . Avatar src = { item . user . avatar } alt = { `${ item . user . avatar } avatar` } />
41-
42- < S . CommentInfos >
43- < S . CommentTitle >
44- < S . UserName > { item . user . name } </ S . UserName >
45- < S . Separator />
46- < S . Date > 22/01/2024</ S . Date >
47- </ S . CommentTitle >
48-
49- < S . Comment >
50- < ViewMarkdown content = { item . comment } />
51- </ S . Comment >
52-
53- < S . ExtraInfo >
54- < S . LikeButton >
55- < Heart />
56- < span > { item . likes } </ span >
57- </ S . LikeButton >
58-
59- < S . ReplyButton onClick = { ( ) => handleReply ( item . id ) } >
60- Responder
61- </ S . ReplyButton >
62- </ S . ExtraInfo >
63-
64- { item . reply ?. length > 0 && (
65- < S . ReplyCount > { item . reply ?. length } respostas</ S . ReplyCount >
66- ) }
67-
68- { replyComment . isReplying && replyComment . id === item . id && (
69- < NewComment />
70- ) }
71- < S . ReplyContainer >
72- { item . reply &&
73- item . reply . map ( ( reply ) => (
74- < S . CommentContainer key = { reply . id } className = "reply" >
75- < S . Avatar
76- src = { reply . user . avatar }
77- alt = { `${ reply . user . avatar } avatar` }
78- className = "reply"
79- />
80-
81- < S . CommentInfos >
82- < S . CommentTitle >
83- < S . UserName > { item . user . name } </ S . UserName >
84- < S . Separator />
85- < S . Date > 2 hours ago</ S . Date >
86- </ S . CommentTitle >
87-
88- < S . Comment >
89- < ViewMarkdown content = { userMention ( reply . comment ) } />
90- </ S . Comment >
91-
92- < S . ExtraInfo >
93- < S . LikeButton >
94- < Heart />
95- < span > { reply . likes } </ span >
96- </ S . LikeButton >
97-
98- < S . ReplyButton onClick = { ( ) => handleReply ( reply . id ) } >
99- Responder
100- </ S . ReplyButton >
101- </ S . ExtraInfo >
102-
103- { replyComment . isReplying &&
104- replyComment . id === reply . id && < NewComment /> }
105- </ S . CommentInfos >
106- </ S . CommentContainer >
107- ) ) }
108- </ S . ReplyContainer >
109- </ S . CommentInfos >
110- </ S . CommentContainer >
26+ < Comment
27+ key = { item . id }
28+ listComment = { item }
29+ currentUser = { currentUser }
30+ handleReply = { handleReply }
31+ replyComment = { replyComment }
32+ >
33+ { item . reply &&
34+ item . reply . map ( ( reply ) => (
35+ < Comment
36+ key = { reply . id }
37+ listComment = { reply }
38+ currentUser = { currentUser }
39+ handleReply = { handleReply }
40+ isReplying = { true }
41+ replyComment = { replyComment }
42+ />
43+ ) ) }
44+ </ Comment >
11145 ) ) }
11246 </ S . Container >
11347 ) ;
0 commit comments