Skip to content

Commit bd33180

Browse files
committed
fix: sort comments
1 parent ae10314 commit bd33180

1 file changed

Lines changed: 39 additions & 37 deletions

File tree

src/App.tsx

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,50 @@ const CommentTree: React.FC<CommentProps> = ({ comments, sub = false }) => {
6363
if (!comments) return null
6464
return (
6565
<ul>
66-
{comments.map((comment) => (
67-
<li
68-
key={comment.rpid}
69-
className='comment-item'
70-
style={{
71-
marginTop: sub ? '10px' : '20px',
72-
}}
73-
>
74-
<img
75-
src={comment.member.avatar}
76-
className='comment-item-avatar'
77-
style={{
78-
width: sub ? '28px' : '40px',
79-
height: sub ? '28px' : '40px',
80-
}}
81-
/>
82-
<div
83-
className='comment-item-content'
66+
{comments
67+
.sort((c1, c2) => c1.ctime - c2.ctime)
68+
.map((comment) => (
69+
<li
70+
key={comment.rpid}
71+
className='comment-item'
8472
style={{
85-
...(!sub && {
86-
display: 'flex',
87-
flexDirection: 'column',
88-
}),
73+
marginTop: sub ? '10px' : '20px',
8974
}}
9075
>
91-
<span className='comment-item-username'>
92-
{comment.member.uname}
93-
</span>
94-
<Highlighter
95-
className='comment-item-message'
96-
highlightClassName='comment-item-highlight'
97-
searchWords={[keyword]}
98-
autoEscape={true}
99-
textToHighlight={comment.content.message}
76+
<img
77+
src={comment.member.avatar}
78+
className='comment-item-avatar'
79+
style={{
80+
width: sub ? '28px' : '40px',
81+
height: sub ? '28px' : '40px',
82+
}}
10083
/>
101-
<div className='comment-item-time'>
102-
{formatDateTime(comment.ctime)}
84+
<div
85+
className='comment-item-content'
86+
style={{
87+
...(!sub && {
88+
display: 'flex',
89+
flexDirection: 'column',
90+
}),
91+
}}
92+
>
93+
<span className='comment-item-username'>
94+
{comment.member.uname}
95+
</span>
96+
<Highlighter
97+
className='comment-item-message'
98+
highlightClassName='comment-item-highlight'
99+
searchWords={[keyword]}
100+
autoEscape={true}
101+
textToHighlight={comment.content.message}
102+
/>
103+
<div className='comment-item-time'>
104+
{formatDateTime(comment.ctime)}
105+
</div>
106+
<CommentTree comments={comment.replies} sub />
103107
</div>
104-
<CommentTree comments={comment.replies} sub />
105-
</div>
106-
</li>
107-
))}
108+
</li>
109+
))}
108110
</ul>
109111
)
110112
}

0 commit comments

Comments
 (0)