Skip to content

Commit 94ff0d4

Browse files
committed
feat: show sub-comments
1 parent 59cada8 commit 94ff0d4

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
margin: 20px 0;
5858
}
5959

60-
#comment-search-root dialog ul {
60+
#comment-search-root dialog .comment-tree {
6161
height: 500px;
6262
overflow: auto;
6363
overscroll-behavior: contain;

src/App.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,9 @@ export default function App() {
3131
}
3232
}}
3333
/>
34-
<ul>
35-
{comments?.map((comment) => (
36-
<li key={comment.rpid} className='comment-item'>
37-
<img
38-
src={comment.member.avatar}
39-
className='comment-item-avatar'
40-
/>
41-
<div className='comment-item-content'>
42-
<span className='comment-item-username'>
43-
{comment.member.uname}
44-
</span>
45-
<span className='comment-item-message'>
46-
{comment.content.message}
47-
</span>
48-
</div>
49-
</li>
50-
))}
51-
</ul>
34+
<div className='comment-tree'>
35+
<CommentTree comments={comments} />
36+
</div>
5237
</dialog>
5338
<button
5439
onClick={() => {
@@ -62,3 +47,28 @@ export default function App() {
6247
</div>
6348
)
6449
}
50+
51+
interface CommentProps {
52+
comments?: Reply[]
53+
}
54+
const CommentTree: React.FC<CommentProps> = ({ comments }) => {
55+
if (!comments) return null
56+
return (
57+
<ul>
58+
{comments?.map((comment) => (
59+
<li key={comment.rpid} className='comment-item'>
60+
<img src={comment.member.avatar} className='comment-item-avatar' />
61+
<div className='comment-item-content'>
62+
<span className='comment-item-username'>
63+
{comment.member.uname}
64+
</span>
65+
<span className='comment-item-message'>
66+
{comment.content.message}
67+
</span>
68+
<CommentTree comments={comment.replies} />
69+
</div>
70+
</li>
71+
))}
72+
</ul>
73+
)
74+
}

0 commit comments

Comments
 (0)