|
1 | 1 | import React from 'react'; |
| 2 | +import dayjs from 'dayjs'; |
| 3 | + |
2 | 4 | import { useParams } from 'umi'; |
3 | 5 | import { useRequest } from 'ahooks'; |
4 | | -import { PageHeader } from 'antd'; |
| 6 | +import { PageHeader, Comment, Avatar, Divider, Space } from 'antd'; |
| 7 | +import { |
| 8 | + LikeFilled, |
| 9 | + EditFilled, |
| 10 | + DeleteFilled, |
| 11 | + CommentOutlined, |
| 12 | +} from '@ant-design/icons'; |
5 | 13 | import * as API from '@/service/topic'; |
6 | 14 |
|
7 | 15 | import MarkdownIt from 'markdown-it'; |
8 | 16 | import MdEditor from 'react-markdown-editor-lite'; |
9 | 17 | import 'react-markdown-editor-lite/lib/index.css'; |
10 | 18 |
|
| 19 | +import SubTitle from './component/SubTitle'; |
| 20 | + |
11 | 21 | import * as styles from './index.less'; |
12 | 22 |
|
13 | | -const mdParser = new MarkdownIt(/* Markdown-it options */); |
| 23 | +const mdParser = new MarkdownIt(); |
14 | 24 |
|
15 | 25 | const TopicDetail: React.FC<React.PropsWithChildren<Props>> = (props) => { |
16 | 26 | const params: Record<string, any> = useParams(); |
@@ -42,24 +52,105 @@ const TopicDetail: React.FC<React.PropsWithChildren<Props>> = (props) => { |
42 | 52 | return null; |
43 | 53 | } |
44 | 54 |
|
| 55 | + const renderComment = () => { |
| 56 | + if (!data) { |
| 57 | + return null; |
| 58 | + } |
| 59 | + |
| 60 | + const { replies } = data; |
| 61 | + |
| 62 | + return ( |
| 63 | + <div className={styles.comment}> |
| 64 | + {replies.map((reply: Reply, index: number) => { |
| 65 | + const { author, content, create_at } = reply; |
| 66 | + return ( |
| 67 | + <> |
| 68 | + {index === replies.length - 1 ? null : ( |
| 69 | + <Divider type="horizontal" /> |
| 70 | + )} |
| 71 | + |
| 72 | + <Comment |
| 73 | + actions={[ |
| 74 | + <LikeFilled />, |
| 75 | + <EditFilled />, |
| 76 | + <DeleteFilled />, |
| 77 | + <CommentOutlined />, |
| 78 | + ]} |
| 79 | + author={ |
| 80 | + <Space size={8}> |
| 81 | + <span>{author.loginname}</span> |
| 82 | + <span> |
| 83 | + {dayjs(create_at).format('YYYY-MM-DD hh:mm:ss')} |
| 84 | + </span> |
| 85 | + </Space> |
| 86 | + } |
| 87 | + avatar={ |
| 88 | + <Avatar src={author.avatar_url} alt={author.loginname} /> |
| 89 | + } |
| 90 | + content={ |
| 91 | + <div |
| 92 | + className={styles.comment_content} |
| 93 | + dangerouslySetInnerHTML={{ |
| 94 | + __html: mdParser.render(content), |
| 95 | + }} |
| 96 | + ></div> |
| 97 | + } |
| 98 | + ></Comment> |
| 99 | + </> |
| 100 | + ); |
| 101 | + })} |
| 102 | + </div> |
| 103 | + ); |
| 104 | + }; |
| 105 | + |
| 106 | + const renderDetail = () => { |
| 107 | + if (!data) { |
| 108 | + return null; |
| 109 | + } |
| 110 | + |
| 111 | + return ( |
| 112 | + <div className={styles.detail}> |
| 113 | + <Divider type="horizontal"></Divider> |
| 114 | + <MdEditor |
| 115 | + className={styles.editor} |
| 116 | + readOnly |
| 117 | + view={{ |
| 118 | + menu: false, |
| 119 | + md: false, |
| 120 | + html: true, |
| 121 | + }} |
| 122 | + value={data.content} |
| 123 | + renderHTML={(text) => mdParser.render(text)} |
| 124 | + // onChange={handleEditorChange} |
| 125 | + /> |
| 126 | + </div> |
| 127 | + ); |
| 128 | + }; |
| 129 | + |
45 | 130 | return ( |
46 | 131 | <PageHeader title={data?.title} onBack={() => window.history.back()}> |
47 | | - <MdEditor |
48 | | - className={styles.editor} |
49 | | - readOnly |
50 | | - view={{ |
51 | | - menu: false, |
52 | | - md: false, |
53 | | - html: true, |
54 | | - }} |
55 | | - value={data.content} |
56 | | - renderHTML={(text) => mdParser.render(text)} |
57 | | - // onChange={handleEditorChange} |
58 | | - /> |
| 132 | + <SubTitle {...data} /> |
| 133 | + {renderDetail()} |
| 134 | + {renderComment()} |
59 | 135 | </PageHeader> |
60 | 136 | ); |
61 | 137 | }; |
62 | 138 |
|
63 | 139 | export default TopicDetail; |
64 | 140 |
|
65 | 141 | interface Props {} |
| 142 | + |
| 143 | +interface Reply { |
| 144 | + id: string; |
| 145 | + content: string; |
| 146 | + |
| 147 | + author: { |
| 148 | + loginname: string; |
| 149 | + avatar_url: string; |
| 150 | + }; |
| 151 | + |
| 152 | + ups: string[]; |
| 153 | + create_at: Date; |
| 154 | + reply_id?: string; |
| 155 | + is_uped: boolean; |
| 156 | +} |
0 commit comments