Revert "[Comments] Batch resolve" (#61)
This reverts commitcaadd889ce
, reversing changes made to8b2c7a2b21
. ## Issue - Infinite `resolve` loop when deleted channel is present in the comments. - Since it was only displayed comments with resolved channels, it masked away those comments. While that may or may not be regarded as a defect, I think we should do it at Commentron instead of at the app if we want to filter deleted channels. I vote to show comments from deleted channels, since it might have good conversation thread.
This commit is contained in:
parent
d5ad63c6e9
commit
0e96f8d468
4 changed files with 114 additions and 147 deletions
|
@ -1,6 +1,5 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
doResolveUris,
|
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
makeSelectClaimIsMine,
|
makeSelectClaimIsMine,
|
||||||
selectFetchingMyChannels,
|
selectFetchingMyChannels,
|
||||||
|
@ -25,21 +24,11 @@ import CommentsList from './view';
|
||||||
|
|
||||||
const select = (state, props) => {
|
const select = (state, props) => {
|
||||||
const activeChannelClaim = selectActiveChannelClaim(state);
|
const activeChannelClaim = selectActiveChannelClaim(state);
|
||||||
const topLevelComments = makeSelectTopLevelCommentsForUri(props.uri)(state);
|
|
||||||
const resolvedComments = [];
|
|
||||||
|
|
||||||
if (topLevelComments.length > 0) {
|
|
||||||
topLevelComments.map(
|
|
||||||
(comment) => Boolean(makeSelectClaimForUri(comment.channel_url)(state)) && resolvedComments.push(comment)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
topLevelComments,
|
|
||||||
resolvedComments,
|
|
||||||
myChannels: selectMyChannelClaims(state),
|
myChannels: selectMyChannelClaims(state),
|
||||||
allCommentIds: makeSelectCommentIdsForUri(props.uri)(state),
|
allCommentIds: makeSelectCommentIdsForUri(props.uri)(state),
|
||||||
pinnedComments: makeSelectPinnedCommentsForUri(props.uri)(state),
|
pinnedComments: makeSelectPinnedCommentsForUri(props.uri)(state),
|
||||||
|
topLevelComments: makeSelectTopLevelCommentsForUri(props.uri)(state),
|
||||||
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(props.uri)(state),
|
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(props.uri)(state),
|
||||||
totalComments: makeSelectTotalCommentsCountForUri(props.uri)(state),
|
totalComments: makeSelectTotalCommentsCountForUri(props.uri)(state),
|
||||||
claim: makeSelectClaimForUri(props.uri)(state),
|
claim: makeSelectClaimForUri(props.uri)(state),
|
||||||
|
@ -60,7 +49,6 @@ const perform = (dispatch) => ({
|
||||||
fetchComment: (commentId) => dispatch(doCommentById(commentId)),
|
fetchComment: (commentId) => dispatch(doCommentById(commentId)),
|
||||||
fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)),
|
fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)),
|
||||||
resetComments: (claimId) => dispatch(doCommentReset(claimId)),
|
resetComments: (claimId) => dispatch(doCommentReset(claimId)),
|
||||||
doResolveUris: (uris) => dispatch(doResolveUris(uris, true)),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(CommentsList);
|
export default connect(select, perform)(CommentsList);
|
||||||
|
|
|
@ -32,7 +32,6 @@ type Props = {
|
||||||
allCommentIds: any,
|
allCommentIds: any,
|
||||||
pinnedComments: Array<Comment>,
|
pinnedComments: Array<Comment>,
|
||||||
topLevelComments: Array<Comment>,
|
topLevelComments: Array<Comment>,
|
||||||
resolvedComments: Array<Comment>,
|
|
||||||
topLevelTotalPages: number,
|
topLevelTotalPages: number,
|
||||||
uri: string,
|
uri: string,
|
||||||
claim: ?Claim,
|
claim: ?Claim,
|
||||||
|
@ -48,9 +47,8 @@ type Props = {
|
||||||
othersReactsById: ?{ [string]: { [REACTION_TYPES.LIKE | REACTION_TYPES.DISLIKE]: number } },
|
othersReactsById: ?{ [string]: { [REACTION_TYPES.LIKE | REACTION_TYPES.DISLIKE]: number } },
|
||||||
activeChannelId: ?string,
|
activeChannelId: ?string,
|
||||||
settingsByChannelId: { [channelId: string]: PerChannelSettings },
|
settingsByChannelId: { [channelId: string]: PerChannelSettings },
|
||||||
commentsAreExpanded?: boolean,
|
|
||||||
fetchReacts: (Array<string>) => Promise<any>,
|
fetchReacts: (Array<string>) => Promise<any>,
|
||||||
doResolveUris: (Array<string>) => void,
|
commentsAreExpanded?: boolean,
|
||||||
fetchTopLevelComments: (string, number, number, number) => void,
|
fetchTopLevelComments: (string, number, number, number) => void,
|
||||||
fetchComment: (string) => void,
|
fetchComment: (string) => void,
|
||||||
resetComments: (string) => void,
|
resetComments: (string) => void,
|
||||||
|
@ -62,7 +60,6 @@ function CommentList(props: Props) {
|
||||||
uri,
|
uri,
|
||||||
pinnedComments,
|
pinnedComments,
|
||||||
topLevelComments,
|
topLevelComments,
|
||||||
resolvedComments,
|
|
||||||
topLevelTotalPages,
|
topLevelTotalPages,
|
||||||
claim,
|
claim,
|
||||||
claimIsMine,
|
claimIsMine,
|
||||||
|
@ -77,9 +74,8 @@ function CommentList(props: Props) {
|
||||||
othersReactsById,
|
othersReactsById,
|
||||||
activeChannelId,
|
activeChannelId,
|
||||||
settingsByChannelId,
|
settingsByChannelId,
|
||||||
commentsAreExpanded,
|
|
||||||
fetchReacts,
|
fetchReacts,
|
||||||
doResolveUris,
|
commentsAreExpanded,
|
||||||
fetchTopLevelComments,
|
fetchTopLevelComments,
|
||||||
fetchComment,
|
fetchComment,
|
||||||
resetComments,
|
resetComments,
|
||||||
|
@ -225,16 +221,8 @@ function CommentList(props: Props) {
|
||||||
}
|
}
|
||||||
}, [hasDefaultExpansion, isFetchingComments, moreBelow, page, readyToDisplayComments, topLevelTotalPages]);
|
}, [hasDefaultExpansion, isFetchingComments, moreBelow, page, readyToDisplayComments, topLevelTotalPages]);
|
||||||
|
|
||||||
// Batch resolve comment channel urls
|
const getCommentElems = (comments) => {
|
||||||
useEffect(() => {
|
return comments.map((comment) => (
|
||||||
const urisToResolve = [];
|
|
||||||
topLevelComments.map(({ channel_url }) => channel_url !== undefined && urisToResolve.push(channel_url));
|
|
||||||
|
|
||||||
if (urisToResolve.length > 0) doResolveUris(urisToResolve);
|
|
||||||
}, [topLevelComments, doResolveUris]);
|
|
||||||
|
|
||||||
const getCommentElems = (comments) =>
|
|
||||||
comments.map((comment) => (
|
|
||||||
<CommentView
|
<CommentView
|
||||||
isTopLevel
|
isTopLevel
|
||||||
threadDepth={3}
|
threadDepth={3}
|
||||||
|
@ -259,8 +247,10 @@ function CommentList(props: Props) {
|
||||||
isFiat={comment.is_fiat}
|
isFiat={comment.is_fiat}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
};
|
||||||
|
|
||||||
const sortButton = (label, icon, sortOption) => (
|
const sortButton = (label, icon, sortOption) => {
|
||||||
|
return (
|
||||||
<Button
|
<Button
|
||||||
button="alt"
|
button="alt"
|
||||||
label={label}
|
label={label}
|
||||||
|
@ -272,6 +262,7 @@ function CommentList(props: Props) {
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
|
@ -308,7 +299,7 @@ function CommentList(props: Props) {
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{readyToDisplayComments && pinnedComments && getCommentElems(pinnedComments)}
|
{readyToDisplayComments && pinnedComments && getCommentElems(pinnedComments)}
|
||||||
{readyToDisplayComments && resolvedComments && getCommentElems(resolvedComments)}
|
{readyToDisplayComments && topLevelComments && getCommentElems(topLevelComments)}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{!hasDefaultExpansion && (
|
{!hasDefaultExpansion && (
|
||||||
|
|
|
@ -1,29 +1,15 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { makeSelectClaimIsMine, selectMyChannelClaims, makeSelectClaimForUri, doResolveUris } from 'lbry-redux';
|
import { makeSelectClaimIsMine, selectMyChannelClaims } from 'lbry-redux';
|
||||||
import { selectIsFetchingCommentsByParentId, makeSelectRepliesForParentId } from 'redux/selectors/comments';
|
import { selectIsFetchingCommentsByParentId, makeSelectRepliesForParentId } from 'redux/selectors/comments';
|
||||||
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||||
import CommentsReplies from './view';
|
import CommentsReplies from './view';
|
||||||
|
|
||||||
const select = (state, props) => {
|
const select = (state, props) => ({
|
||||||
const fetchedReplies = makeSelectRepliesForParentId(props.parentId)(state);
|
fetchedReplies: makeSelectRepliesForParentId(props.parentId)(state),
|
||||||
const resolvedReplies = [];
|
|
||||||
|
|
||||||
if (fetchedReplies && fetchedReplies.length > 0) {
|
|
||||||
fetchedReplies.map(
|
|
||||||
(comment) => Boolean(makeSelectClaimForUri(comment.channel_url)(state)) && resolvedReplies.push(comment)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
fetchedReplies,
|
|
||||||
resolvedReplies,
|
|
||||||
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
|
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
|
||||||
userCanComment: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
|
commentingEnabled: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
|
||||||
myChannels: selectMyChannelClaims(state),
|
myChannels: selectMyChannelClaims(state),
|
||||||
isFetchingByParentId: selectIsFetchingCommentsByParentId(state),
|
isFetchingByParentId: selectIsFetchingCommentsByParentId(state),
|
||||||
};
|
});
|
||||||
};
|
|
||||||
|
|
||||||
const perform = (dispatch) => ({ doResolveUris: (uris) => dispatch(doResolveUris(uris, true)) });
|
export default connect(select)(CommentsReplies);
|
||||||
|
|
||||||
export default connect(select, perform)(CommentsReplies);
|
|
||||||
|
|
|
@ -1,26 +1,24 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as ICONS from 'constants/icons';
|
import * as ICONS from 'constants/icons';
|
||||||
import Button from 'component/button';
|
|
||||||
import Comment from 'component/comment';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import Comment from 'component/comment';
|
||||||
|
import Button from 'component/button';
|
||||||
import Spinner from 'component/spinner';
|
import Spinner from 'component/spinner';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
fetchedReplies: Array<Comment>,
|
fetchedReplies: Array<any>,
|
||||||
resolvedReplies: Array<Comment>,
|
|
||||||
uri: string,
|
uri: string,
|
||||||
parentId: string,
|
parentId: string,
|
||||||
claimIsMine: boolean,
|
claimIsMine: boolean,
|
||||||
myChannels: ?Array<ChannelClaim>,
|
myChannels: ?Array<ChannelClaim>,
|
||||||
linkedCommentId?: string,
|
linkedCommentId?: string,
|
||||||
userCanComment: boolean,
|
commentingEnabled: 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,
|
||||||
doResolveUris: (Array<string>) => void,
|
|
||||||
onShowMore?: () => void,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function CommentsReplies(props: Props) {
|
function CommentsReplies(props: Props) {
|
||||||
|
@ -28,36 +26,44 @@ function CommentsReplies(props: Props) {
|
||||||
uri,
|
uri,
|
||||||
parentId,
|
parentId,
|
||||||
fetchedReplies,
|
fetchedReplies,
|
||||||
resolvedReplies,
|
|
||||||
claimIsMine,
|
claimIsMine,
|
||||||
myChannels,
|
myChannels,
|
||||||
linkedCommentId,
|
linkedCommentId,
|
||||||
userCanComment,
|
commentingEnabled,
|
||||||
threadDepth,
|
threadDepth,
|
||||||
numDirectReplies,
|
numDirectReplies,
|
||||||
isFetchingByParentId,
|
isFetchingByParentId,
|
||||||
|
onShowMore,
|
||||||
hasMore,
|
hasMore,
|
||||||
supportDisabled,
|
supportDisabled,
|
||||||
doResolveUris,
|
|
||||||
onShowMore,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [isExpanded, setExpanded] = React.useState(true);
|
const [isExpanded, setExpanded] = React.useState(true);
|
||||||
const isResolvingReplies = fetchedReplies && resolvedReplies.length !== fetchedReplies.length;
|
|
||||||
|
|
||||||
// Batch resolve comment channel urls
|
function showMore() {
|
||||||
React.useEffect(() => {
|
if (onShowMore) {
|
||||||
if (!fetchedReplies) return;
|
onShowMore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const urisToResolve = [];
|
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
|
||||||
fetchedReplies.map(({ channel_url }) => channel_url !== undefined && urisToResolve.push(channel_url));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if (urisToResolve.length > 0) doResolveUris(urisToResolve);
|
const displayedComments = fetchedReplies;
|
||||||
}, [fetchedReplies, doResolveUris]);
|
|
||||||
|
|
||||||
return !numDirectReplies ? null : (
|
return (
|
||||||
|
Boolean(numDirectReplies) && (
|
||||||
<div className="comment__replies-container">
|
<div className="comment__replies-container">
|
||||||
{!isExpanded ? (
|
{Boolean(numDirectReplies) && !isExpanded && (
|
||||||
<div className="comment__actions--nested">
|
<div className="comment__actions--nested">
|
||||||
<Button
|
<Button
|
||||||
className="comment__action"
|
className="comment__action"
|
||||||
|
@ -66,14 +72,16 @@ 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">
|
||||||
{!isResolvingReplies &&
|
{displayedComments &&
|
||||||
resolvedReplies.length > 0 &&
|
displayedComments.map((comment) => {
|
||||||
resolvedReplies.map((comment) => (
|
return (
|
||||||
<Comment
|
<Comment
|
||||||
threadDepth={threadDepth}
|
threadDepth={threadDepth}
|
||||||
uri={uri}
|
uri={uri}
|
||||||
|
@ -85,34 +93,27 @@ function CommentsReplies(props: Props) {
|
||||||
message={comment.comment}
|
message={comment.comment}
|
||||||
timePosted={comment.timestamp * 1000}
|
timePosted={comment.timestamp * 1000}
|
||||||
claimIsMine={claimIsMine}
|
claimIsMine={claimIsMine}
|
||||||
commentIsMine={
|
commentIsMine={comment.channel_id && isMyComment(comment.channel_id)}
|
||||||
comment.channel_id &&
|
|
||||||
myChannels &&
|
|
||||||
myChannels.some(({ claim_id }) => claim_id === comment.channel_id)
|
|
||||||
}
|
|
||||||
linkedCommentId={linkedCommentId}
|
linkedCommentId={linkedCommentId}
|
||||||
commentingEnabled={userCanComment}
|
commentingEnabled={commentingEnabled}
|
||||||
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 button="link" label={__('Show more')} onClick={showMore} className="button--uri-indicator" />
|
||||||
button="link"
|
|
||||||
label={__('Show more')}
|
|
||||||
onClick={() => onShowMore && onShowMore()}
|
|
||||||
className="button--uri-indicator"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(isFetchingByParentId[parentId] || isResolvingReplies) && (
|
{isFetchingByParentId[parentId] && (
|
||||||
<div className="comment__replies-container">
|
<div className="comment__replies-container">
|
||||||
<div className="comment__actions--nested">
|
<div className="comment__actions--nested">
|
||||||
<Spinner type="small" />
|
<Spinner type="small" />
|
||||||
|
@ -120,6 +121,7 @@ function CommentsReplies(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue