2020-08-24 19:35:21 +02:00
|
|
|
// @flow
|
2020-08-25 21:54:06 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2020-08-24 19:35:21 +02:00
|
|
|
import React from 'react';
|
|
|
|
import Comment from 'component/comment';
|
|
|
|
import Button from 'component/button';
|
2021-07-15 16:43:28 +02:00
|
|
|
import Spinner from 'component/spinner';
|
2020-08-24 19:35:21 +02:00
|
|
|
|
|
|
|
type Props = {
|
2021-07-15 16:43:28 +02:00
|
|
|
fetchedReplies: Array<any>,
|
2020-08-24 19:35:21 +02:00
|
|
|
uri: string,
|
2021-07-15 16:43:28 +02:00
|
|
|
parentId: string,
|
2020-08-24 19:35:21 +02:00
|
|
|
claimIsMine: boolean,
|
|
|
|
myChannels: ?Array<ChannelClaim>,
|
2021-07-15 16:43:28 +02:00
|
|
|
linkedCommentId?: string,
|
2020-08-24 19:35:21 +02:00
|
|
|
commentingEnabled: boolean,
|
2020-10-07 21:14:52 +02:00
|
|
|
threadDepth: number,
|
2021-08-04 17:01:31 +02:00
|
|
|
numDirectReplies: number, // Total replies for parentId as reported by 'comment[replies]'. Includes blocked items.
|
2021-07-15 16:43:28 +02:00
|
|
|
isFetchingByParentId: { [string]: boolean },
|
|
|
|
onShowMore?: () => void,
|
2021-08-04 17:01:31 +02:00
|
|
|
hasMore: boolean,
|
2021-08-27 12:29:58 +02:00
|
|
|
supportDisabled: boolean,
|
2020-08-24 19:35:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function CommentsReplies(props: Props) {
|
2021-07-15 16:43:28 +02:00
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
parentId,
|
|
|
|
fetchedReplies,
|
|
|
|
claimIsMine,
|
|
|
|
myChannels,
|
|
|
|
linkedCommentId,
|
|
|
|
commentingEnabled,
|
|
|
|
threadDepth,
|
|
|
|
numDirectReplies,
|
|
|
|
isFetchingByParentId,
|
|
|
|
onShowMore,
|
2021-08-04 17:01:31 +02:00
|
|
|
hasMore,
|
2021-08-27 12:29:58 +02:00
|
|
|
supportDisabled,
|
2021-07-15 16:43:28 +02:00
|
|
|
} = props;
|
|
|
|
|
2020-10-07 21:14:52 +02:00
|
|
|
const [isExpanded, setExpanded] = React.useState(true);
|
2020-08-24 19:35:21 +02:00
|
|
|
|
2020-08-25 21:54:06 +02:00
|
|
|
function showMore() {
|
2021-07-15 16:43:28 +02:00
|
|
|
if (onShowMore) {
|
|
|
|
onShowMore();
|
2020-08-24 19:35:21 +02:00
|
|
|
}
|
2020-08-25 21:54:06 +02:00
|
|
|
}
|
2020-08-24 19:35:21 +02:00
|
|
|
|
|
|
|
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
|
2020-08-25 21:54:06 +02:00
|
|
|
function isMyComment(channelId: string) {
|
2020-08-24 19:35:21 +02:00
|
|
|
if (myChannels != null && channelId != null) {
|
|
|
|
for (let i = 0; i < myChannels.length; i++) {
|
|
|
|
if (myChannels[i].claim_id === channelId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2020-08-25 21:54:06 +02:00
|
|
|
}
|
2020-08-24 19:35:21 +02:00
|
|
|
|
2021-07-15 16:43:28 +02:00
|
|
|
const displayedComments = fetchedReplies;
|
2020-08-24 19:35:21 +02:00
|
|
|
|
|
|
|
return (
|
2021-07-15 16:43:28 +02:00
|
|
|
Boolean(numDirectReplies) && (
|
2020-09-11 19:51:31 +02:00
|
|
|
<div className="comment__replies-container">
|
2021-07-15 16:43:28 +02:00
|
|
|
{Boolean(numDirectReplies) && !isExpanded && (
|
2020-09-11 19:51:31 +02:00
|
|
|
<div className="comment__actions--nested">
|
|
|
|
<Button
|
|
|
|
className="comment__action"
|
2020-10-07 21:14:52 +02:00
|
|
|
label={__('Show Replies')}
|
2020-09-11 19:51:31 +02:00
|
|
|
onClick={() => setExpanded(!isExpanded)}
|
|
|
|
icon={isExpanded ? ICONS.UP : ICONS.DOWN}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-08-24 19:35:21 +02:00
|
|
|
)}
|
2021-07-15 17:31:42 +02:00
|
|
|
{isExpanded && (
|
2020-09-11 19:51:31 +02:00
|
|
|
<div>
|
|
|
|
<div className="comment__replies">
|
|
|
|
<Button className="comment__threadline" aria-label="Hide Replies" onClick={() => setExpanded(false)} />
|
2020-08-24 19:35:21 +02:00
|
|
|
|
2020-09-11 19:51:31 +02:00
|
|
|
<ul className="comments--replies">
|
2021-07-15 17:31:42 +02:00
|
|
|
{displayedComments &&
|
|
|
|
displayedComments.map((comment) => {
|
|
|
|
return (
|
|
|
|
<Comment
|
|
|
|
threadDepth={threadDepth}
|
|
|
|
uri={uri}
|
|
|
|
authorUri={comment.channel_url}
|
|
|
|
author={comment.channel_name}
|
|
|
|
claimId={comment.claim_id}
|
|
|
|
commentId={comment.comment_id}
|
|
|
|
key={comment.comment_id}
|
|
|
|
message={comment.comment}
|
|
|
|
timePosted={comment.timestamp * 1000}
|
|
|
|
claimIsMine={claimIsMine}
|
|
|
|
commentIsMine={comment.channel_id && isMyComment(comment.channel_id)}
|
|
|
|
linkedCommentId={linkedCommentId}
|
|
|
|
commentingEnabled={commentingEnabled}
|
|
|
|
supportAmount={comment.support_amount}
|
|
|
|
numDirectReplies={comment.replies}
|
2021-07-23 12:26:16 +02:00
|
|
|
isModerator={comment.is_moderator}
|
|
|
|
isGlobalMod={comment.is_global_mod}
|
2021-08-27 12:29:58 +02:00
|
|
|
supportDisabled={supportDisabled}
|
2021-07-15 17:31:42 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
2020-09-11 19:51:31 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
2020-08-24 19:35:21 +02:00
|
|
|
</div>
|
2020-09-11 19:51:31 +02:00
|
|
|
)}
|
2021-08-04 17:01:31 +02:00
|
|
|
{isExpanded && fetchedReplies && hasMore && (
|
2021-07-15 16:43:28 +02:00
|
|
|
<div className="comment__actions--nested">
|
2020-09-11 19:51:31 +02:00
|
|
|
<Button button="link" label={__('Show more')} onClick={showMore} className="button--uri-indicator" />
|
|
|
|
</div>
|
|
|
|
)}
|
2021-07-15 16:43:28 +02:00
|
|
|
{isFetchingByParentId[parentId] && (
|
|
|
|
<div className="comment__replies-container">
|
|
|
|
<div className="comment__actions--nested">
|
|
|
|
<Spinner type="small" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-09-11 19:51:31 +02:00
|
|
|
</div>
|
|
|
|
)
|
2020-08-24 19:35:21 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CommentsReplies;
|