Handle the case of all replies are blocked.

In this scenario, `comment.List` does not return `comment`. I was expecting an empty array.

Handled accordingly.
This commit is contained in:
infinite-persistence 2021-07-15 23:31:42 +08:00 committed by jessopb
parent 08c701ba19
commit a13708f4dd
2 changed files with 33 additions and 52 deletions

View file

@ -72,33 +72,34 @@ function CommentsReplies(props: Props) {
/> />
</div> </div>
)} )}
{fetchedReplies && displayedComments && isExpanded && ( {isExpanded && (
<div> <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.map((comment) => { {displayedComments &&
return ( displayedComments.map((comment) => {
<Comment return (
threadDepth={threadDepth} <Comment
uri={uri} threadDepth={threadDepth}
authorUri={comment.channel_url} uri={uri}
author={comment.channel_name} authorUri={comment.channel_url}
claimId={comment.claim_id} author={comment.channel_name}
commentId={comment.comment_id} claimId={comment.claim_id}
key={comment.comment_id} commentId={comment.comment_id}
message={comment.comment} key={comment.comment_id}
timePosted={comment.timestamp * 1000} message={comment.comment}
claimIsMine={claimIsMine} timePosted={comment.timestamp * 1000}
commentIsMine={comment.channel_id && isMyComment(comment.channel_id)} claimIsMine={claimIsMine}
linkedCommentId={linkedCommentId} commentIsMine={comment.channel_id && isMyComment(comment.channel_id)}
commentingEnabled={commentingEnabled} linkedCommentId={linkedCommentId}
supportAmount={comment.support_amount} commentingEnabled={commentingEnabled}
numDirectReplies={comment.replies} supportAmount={comment.support_amount}
/> numDirectReplies={comment.replies}
); />
})} );
})}
{totalReplies < numDirectReplies && ( {totalReplies < numDirectReplies && (
<li className="comment comment--reply"> <li className="comment comment--reply">
<div className="comment__content"> <div className="comment__content">

View file

@ -4,8 +4,6 @@ import { handleActions } from 'util/redux-utils';
import { BLOCK_LEVEL } from 'constants/comment'; import { BLOCK_LEVEL } from 'constants/comment';
import { isURIEqual } from 'lbry-redux'; import { isURIEqual } from 'lbry-redux';
const IS_DEV = process.env.NODE_ENV !== 'production';
const defaultState: CommentsState = { const defaultState: CommentsState = {
commentById: {}, // commentId -> Comment commentById: {}, // commentId -> Comment
byId: {}, // ClaimID -> list of fetched comment IDs. byId: {}, // ClaimID -> list of fetched comment IDs.
@ -277,6 +275,15 @@ export default handleActions(
const totalRepliesByParentId = Object.assign({}, state.totalRepliesByParentId); const totalRepliesByParentId = Object.assign({}, state.totalRepliesByParentId);
const isLoadingByParentId = Object.assign({}, state.isLoadingByParentId); const isLoadingByParentId = Object.assign({}, state.isLoadingByParentId);
if (!parentId) {
totalCommentsById[claimId] = totalItems;
topLevelTotalCommentsById[claimId] = totalFilteredItems;
topLevelTotalPagesById[claimId] = totalPages;
} else {
totalRepliesByParentId[parentId] = totalFilteredItems;
isLoadingByParentId[parentId] = false;
}
const commonUpdateAction = (comment, commentById, commentIds, index) => { const commonUpdateAction = (comment, commentById, commentIds, index) => {
// map the comment_ids to the new comments // map the comment_ids to the new comments
commentById[comment.comment_id] = comment; commentById[comment.comment_id] = comment;
@ -289,46 +296,19 @@ export default handleActions(
// sort comments by their timestamp // sort comments by their timestamp
const commentIds = Array(comments.length); const commentIds = Array(comments.length);
// totalCommentsById[claimId] = totalItems;
// --> currently, this value is only correct when done via a top-level query.
// Until this is fixed, I'm moving it downwards to **
// --- Top-level comments --- // --- Top-level comments ---
if (!parentId) { if (!parentId) {
totalCommentsById[claimId] = totalItems; // **
topLevelTotalCommentsById[claimId] = totalFilteredItems;
topLevelTotalPagesById[claimId] = totalPages;
if (!topLevelCommentsById[claimId]) {
topLevelCommentsById[claimId] = [];
}
const topLevelCommentIds = topLevelCommentsById[claimId];
for (let i = 0; i < comments.length; ++i) { for (let i = 0; i < comments.length; ++i) {
const comment = comments[i]; const comment = comments[i];
commonUpdateAction(comment, commentById, commentIds, i); commonUpdateAction(comment, commentById, commentIds, i);
pushToArrayInObject(topLevelCommentsById, claimId, comment.comment_id);
if (IS_DEV && comment['parent_id']) console.error('Invalid top-level comment:', comment); // eslint-disable-line
if (!topLevelCommentIds.includes(comment.comment_id)) {
topLevelCommentIds.push(comment.comment_id);
}
} }
} }
// --- Replies --- // --- Replies ---
else { else {
totalRepliesByParentId[parentId] = totalFilteredItems;
isLoadingByParentId[parentId] = false;
for (let i = 0; i < comments.length; ++i) { for (let i = 0; i < comments.length; ++i) {
const comment = comments[i]; const comment = comments[i];
commonUpdateAction(comment, commentById, commentIds, i); commonUpdateAction(comment, commentById, commentIds, i);
if (IS_DEV && !comment['parent_id']) console.error('Missing parent_id:', comment); // eslint-disable-line
if (IS_DEV && comment.parent_id !== parentId) console.error('Black sheep in the family?:', comment); // eslint-disable-line
pushToArrayInObject(repliesByParentId, parentId, comment.comment_id); pushToArrayInObject(repliesByParentId, parentId, comment.comment_id);
} }
} }