lbry-desktop/ui/component/commentsReplies/view.jsx

92 lines
2.5 KiB
React
Raw Normal View History

2020-08-24 19:35:21 +02:00
// @flow
2020-08-25 21:54:06 +02:00
import * as ICONS from 'constants/icons';
import Button from 'component/button';
import Comment from 'component/comment';
import React from 'react';
import Spinner from 'component/spinner';
2020-08-24 19:35:21 +02:00
type Props = {
uri: string,
linkedCommentId?: string,
2020-10-07 21:14:52 +02:00
threadDepth: number,
numDirectReplies: number, // Total replies for parentId as reported by 'comment[replies]'. Includes blocked items.
hasMore: boolean,
2021-08-27 12:29:58 +02:00
supportDisabled: boolean,
onShowMore?: () => void,
// redux
fetchedReplies: Array<Comment>,
claimIsMine: boolean,
isFetching: boolean,
2020-08-24 19:35:21 +02:00
};
export default function CommentsReplies(props: Props) {
const {
uri,
fetchedReplies,
claimIsMine,
linkedCommentId,
threadDepth,
numDirectReplies,
isFetching,
hasMore,
2021-08-27 12:29:58 +02:00
supportDisabled,
onShowMore,
} = props;
2020-10-07 21:14:52 +02:00
const [isExpanded, setExpanded] = React.useState(true);
return !numDirectReplies ? null : (
<div className="comment__replies-container">
{!isExpanded ? (
<div className="comment__actions--nested">
<Button
className="comment__action"
label={__('Show Replies')}
onClick={() => setExpanded(!isExpanded)}
icon={isExpanded ? ICONS.UP : ICONS.DOWN}
/>
</div>
) : (
<div className="comment__replies">
{fetchedReplies.length > 0 && (
<Button className="comment__threadline" aria-label="Hide Replies" onClick={() => setExpanded(false)} />
)}
2020-08-24 19:35:21 +02:00
<ul className="comments--replies">
{fetchedReplies.map((comment) => (
<Comment
key={comment.comment_id}
threadDepth={threadDepth}
uri={uri}
comment={comment}
claimIsMine={claimIsMine}
linkedCommentId={linkedCommentId}
supportDisabled={supportDisabled}
/>
))}
</ul>
</div>
)}
{isExpanded && fetchedReplies && hasMore && (
<div className="comment__actions--nested">
<Button
button="link"
label={__('Show more')}
onClick={() => onShowMore && onShowMore()}
className="button--uri-indicator"
/>
</div>
)}
{isFetching && (
<div className="comment__replies-container">
<div className="comment__actions--nested">
<Spinner type="small" />
</div>
</div>
)}
</div>
2020-08-24 19:35:21 +02:00
);
}