forked from decred/politeiagui
/
Comment.jsx
179 lines (172 loc) · 4.94 KB
/
Comment.jsx
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import React from "react";
import PropTypes from "prop-types";
import {
Text,
classNames,
useMediaQuery,
useTheme,
DEFAULT_DARK_THEME_NAME
} from "pi-ui";
import styles from "./Comment.module.css";
import DateTooltip from "src/components/DateTooltip";
import Markdown from "src/components/Markdown";
import Join from "src/components/Join";
import Link from "src/components/Link";
import LoggedInContent from "src/components/LoggedInContent";
import Likes from "src/components/Likes";
import CopyLink from "src/components/CopyLink";
import { useConfig } from "src/containers/Config";
import { NOJS_ROUTE_PREFIX } from "src/constants";
const Comment = ({
className,
permalink,
author,
authorID,
createdAt,
censored,
highlightAuthor,
likesUpCount,
likesDownCount,
likeOption,
disableLikes,
disableLikesClick,
onLike,
onDislike,
commentBody,
showReplies,
disableReply,
onClickCensor,
onClickReply,
onClickShowReplies,
numOfReplies,
numOfNewHiddenReplies,
highlightAsNew,
censorable,
isFlatMode,
seeInContextLink,
...props
}) => {
const extraSmall = useMediaQuery("(max-width: 560px)");
const { javascriptEnabled } = useConfig();
const censorButton = !censored && censorable && (
<Text weight="semibold" className={styles.censor} onClick={onClickCensor}>
Censor
</Text>
);
const { themeName } = useTheme();
const isDarkTheme = themeName === DEFAULT_DARK_THEME_NAME;
const showNewReplies =
numOfNewHiddenReplies > 0 && !showReplies && !isFlatMode;
const isThread = numOfReplies > 0 && !isFlatMode;
const authorURL = javascriptEnabled
? `/user/${authorID}`
: `${NOJS_ROUTE_PREFIX}/user/${authorID}`;
return (
<div
className={classNames(
styles.commentWrapper,
highlightAsNew && styles.highlightAsNew,
className
)}
{...props}>
<div className={classNames("justify-space-between", styles.info)}>
<Join>
<Link
className={classNames(
styles.commentAuthor,
highlightAuthor && styles.recordAuthor
)}
to={authorURL}>
{author}
</Link>
<DateTooltip timestamp={createdAt} placement="bottom">
{({ timeAgo }) => (
<Link className={styles.timeAgo} to={permalink}>
{timeAgo}
</Link>
)}
</DateTooltip>
{highlightAsNew && !extraSmall && <Text color="gray">new</Text>}
{!extraSmall && censorButton}
{!extraSmall && seeInContextLink}
</Join>
{!disableLikes && !censored && (
<div className={styles.likesWrapper}>
<Likes
disabled={disableLikesClick}
upLikes={likesUpCount}
downLikes={likesDownCount}
option={likeOption}
onLike={onLike}
onDislike={onDislike}
/>
</div>
)}
</div>
{extraSmall && censorButton}
{extraSmall && seeInContextLink}
{!censored ? (
<Markdown
filterUrl={true}
renderImages={false}
className={classNames(isDarkTheme && "dark", "margin-top-s")}
body={commentBody}
/>
) : (
<Markdown
renderImages={false}
className={styles.censored}
body="Censored by moderators "
/>
)}
<div className="justify-space-between margin-top-s">
<div className="justify-left">
{!disableReply && (
<LoggedInContent>
<Text
weight="semibold"
className={styles.reply}
onClick={onClickReply}>
Reply
</Text>
</LoggedInContent>
)}
{isThread && (
<span className={styles.showReplies} onClick={onClickShowReplies}>
{showReplies ? "-" : `+${numOfReplies}`}
</span>
)}
{showNewReplies && (
<Text color="green">{`${numOfNewHiddenReplies} new`}</Text>
)}
</div>
<CopyLink url={window.location.origin + permalink} />
</div>
</div>
);
};
Comment.propTypes = {
className: PropTypes.string,
permalink: PropTypes.string,
author: PropTypes.string,
authorID: PropTypes.string,
createdAt: PropTypes.number,
highlightAuthor: PropTypes.bool,
disableLikes: PropTypes.bool,
likesCount: PropTypes.number,
likesUpCount: PropTypes.number,
likesDownCount: PropTypes.number,
likeOption: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
disableLikesClick: PropTypes.bool,
onLike: PropTypes.func,
onDislike: PropTypes.func,
commentBody: PropTypes.string,
showReplies: PropTypes.bool,
disableReply: PropTypes.bool,
onClickReply: PropTypes.func,
onClickShowReplies: PropTypes.func,
numOfReplies: PropTypes.number,
numOfNewHiddenReplies: PropTypes.number,
censorable: PropTypes.bool
};
export default React.memo(Comment);