Comment.tsx
1.09 KB
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
import React, { useState } from 'react';
import { Comment as CommentItem, Divider } from 'antd';
import Profile from './Profile';
import Datetime from './Datetime';
import Like from './Like';
import Dislike from './Dislike';
export default function Comment({
author,
content,
created_date,
idx,
commentsNum,
}) {
const [likes, setLikes] = useState(0);
const [dislikes, setDislikes] = useState(0);
const [action, setAction] = useState(null);
const like = () => {
setLikes(1);
setDislikes(0);
setAction('liked');
};
const dislike = () => {
setLikes(0);
setDislikes(1);
setAction('disliked');
};
return (
<>
<CommentItem
actions={[
Like({ action, like, likes }),
Dislike({
action,
dislike,
dislikes,
}),
]}
author={<a>{author}</a>}
avatar={Profile({ src: '', author })}
content={<div dangerouslySetInnerHTML={{ __html: content }} />}
datetime={Datetime({ created_date })}
/>
{commentsNum - 1 !== idx && <Divider />}
</>
);
}