mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-23 17:47:24 +00:00
Refactor commentsReplies
This commit is contained in:
parent
f7cb39c496
commit
cafefb2a33
2 changed files with 68 additions and 86 deletions
|
@ -7,7 +7,7 @@ import CommentsReplies from './view';
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
fetchedReplies: makeSelectRepliesForParentId(props.parentId)(state),
|
fetchedReplies: makeSelectRepliesForParentId(props.parentId)(state),
|
||||||
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
|
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
|
||||||
commentingEnabled: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
|
userCanComment: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
|
||||||
myChannels: selectMyChannelClaims(state),
|
myChannels: selectMyChannelClaims(state),
|
||||||
isFetchingByParentId: selectIsFetchingCommentsByParentId(state),
|
isFetchingByParentId: selectIsFetchingCommentsByParentId(state),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as ICONS from 'constants/icons';
|
import * as ICONS from 'constants/icons';
|
||||||
import React from 'react';
|
|
||||||
import Comment from 'component/comment';
|
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
import Comment from 'component/comment';
|
||||||
|
import React from 'react';
|
||||||
import Spinner from 'component/spinner';
|
import Spinner from 'component/spinner';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -12,13 +12,13 @@ type Props = {
|
||||||
claimIsMine: boolean,
|
claimIsMine: boolean,
|
||||||
myChannels: ?Array<ChannelClaim>,
|
myChannels: ?Array<ChannelClaim>,
|
||||||
linkedCommentId?: string,
|
linkedCommentId?: string,
|
||||||
commentingEnabled: boolean,
|
userCanComment: boolean,
|
||||||
threadDepth: number,
|
threadDepth: number,
|
||||||
numDirectReplies: number, // Total replies for parentId as reported by 'comment[replies]'. Includes blocked items.
|
numDirectReplies: number, // Total replies for parentId as reported by 'comment[replies]'. Includes blocked items.
|
||||||
isFetchingByParentId: { [string]: boolean },
|
isFetchingByParentId: { [string]: boolean },
|
||||||
onShowMore?: () => void,
|
|
||||||
hasMore: boolean,
|
hasMore: boolean,
|
||||||
supportDisabled: boolean,
|
supportDisabled: boolean,
|
||||||
|
onShowMore?: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
function CommentsReplies(props: Props) {
|
function CommentsReplies(props: Props) {
|
||||||
|
@ -29,41 +29,20 @@ function CommentsReplies(props: Props) {
|
||||||
claimIsMine,
|
claimIsMine,
|
||||||
myChannels,
|
myChannels,
|
||||||
linkedCommentId,
|
linkedCommentId,
|
||||||
commentingEnabled,
|
userCanComment,
|
||||||
threadDepth,
|
threadDepth,
|
||||||
numDirectReplies,
|
numDirectReplies,
|
||||||
isFetchingByParentId,
|
isFetchingByParentId,
|
||||||
onShowMore,
|
|
||||||
hasMore,
|
hasMore,
|
||||||
supportDisabled,
|
supportDisabled,
|
||||||
|
onShowMore,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [isExpanded, setExpanded] = React.useState(true);
|
const [isExpanded, setExpanded] = React.useState(true);
|
||||||
|
|
||||||
function showMore() {
|
return !numDirectReplies ? null : (
|
||||||
if (onShowMore) {
|
|
||||||
onShowMore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
|
|
||||||
function isMyComment(channelId: string) {
|
|
||||||
if (myChannels != null && channelId != null) {
|
|
||||||
for (let i = 0; i < myChannels.length; i++) {
|
|
||||||
if (myChannels[i].claim_id === channelId) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const displayedComments = fetchedReplies;
|
|
||||||
|
|
||||||
return (
|
|
||||||
Boolean(numDirectReplies) && (
|
|
||||||
<div className="comment__replies-container">
|
<div className="comment__replies-container">
|
||||||
{Boolean(numDirectReplies) && !isExpanded && (
|
{!isExpanded ? (
|
||||||
<div className="comment__actions--nested">
|
<div className="comment__actions--nested">
|
||||||
<Button
|
<Button
|
||||||
className="comment__action"
|
className="comment__action"
|
||||||
|
@ -72,16 +51,13 @@ function CommentsReplies(props: Props) {
|
||||||
icon={isExpanded ? ICONS.UP : ICONS.DOWN}
|
icon={isExpanded ? ICONS.UP : ICONS.DOWN}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : (
|
||||||
{isExpanded && (
|
|
||||||
<div>
|
|
||||||
<div className="comment__replies">
|
<div className="comment__replies">
|
||||||
<Button className="comment__threadline" aria-label="Hide Replies" onClick={() => setExpanded(false)} />
|
<Button className="comment__threadline" aria-label="Hide Replies" onClick={() => setExpanded(false)} />
|
||||||
|
|
||||||
<ul className="comments--replies">
|
<ul className="comments--replies">
|
||||||
{displayedComments &&
|
{fetchedReplies &&
|
||||||
displayedComments.map((comment) => {
|
fetchedReplies.map((comment) => (
|
||||||
return (
|
|
||||||
<Comment
|
<Comment
|
||||||
threadDepth={threadDepth}
|
threadDepth={threadDepth}
|
||||||
uri={uri}
|
uri={uri}
|
||||||
|
@ -93,24 +69,31 @@ function CommentsReplies(props: Props) {
|
||||||
message={comment.comment}
|
message={comment.comment}
|
||||||
timePosted={comment.timestamp * 1000}
|
timePosted={comment.timestamp * 1000}
|
||||||
claimIsMine={claimIsMine}
|
claimIsMine={claimIsMine}
|
||||||
commentIsMine={comment.channel_id && isMyComment(comment.channel_id)}
|
commentIsMine={
|
||||||
|
comment.channel_id &&
|
||||||
|
myChannels &&
|
||||||
|
myChannels.some(({ claim_id }) => claim_id === comment.channel_id)
|
||||||
|
}
|
||||||
linkedCommentId={linkedCommentId}
|
linkedCommentId={linkedCommentId}
|
||||||
commentingEnabled={commentingEnabled}
|
commentingEnabled={userCanComment}
|
||||||
supportAmount={comment.support_amount}
|
supportAmount={comment.support_amount}
|
||||||
numDirectReplies={comment.replies}
|
numDirectReplies={comment.replies}
|
||||||
isModerator={comment.is_moderator}
|
isModerator={comment.is_moderator}
|
||||||
isGlobalMod={comment.is_global_mod}
|
isGlobalMod={comment.is_global_mod}
|
||||||
supportDisabled={supportDisabled}
|
supportDisabled={supportDisabled}
|
||||||
/>
|
/>
|
||||||
);
|
))}
|
||||||
})}
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
{isExpanded && fetchedReplies && hasMore && (
|
{isExpanded && fetchedReplies && hasMore && (
|
||||||
<div className="comment__actions--nested">
|
<div className="comment__actions--nested">
|
||||||
<Button button="link" label={__('Show more')} onClick={showMore} className="button--uri-indicator" />
|
<Button
|
||||||
|
button="link"
|
||||||
|
label={__('Show more')}
|
||||||
|
onClick={() => onShowMore && onShowMore()}
|
||||||
|
className="button--uri-indicator"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{isFetchingByParentId[parentId] && (
|
{isFetchingByParentId[parentId] && (
|
||||||
|
@ -121,7 +104,6 @@ function CommentsReplies(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue