[Comments] Batch resolve #7236
2 changed files with 42 additions and 21 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
|
doResolveUris,
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
makeSelectClaimIsMine,
|
makeSelectClaimIsMine,
|
||||||
selectFetchingMyChannels,
|
selectFetchingMyChannels,
|
||||||
|
@ -24,11 +25,21 @@ 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),
|
||||||
|
@ -49,6 +60,7 @@ 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,6 +32,7 @@ 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,
|
||||||
|
@ -47,8 +48,9 @@ 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 },
|
||||||
fetchReacts: (Array<string>) => Promise<any>,
|
|
||||||
commentsAreExpanded?: boolean,
|
commentsAreExpanded?: boolean,
|
||||||
|
fetchReacts: (Array<string>) => Promise<any>,
|
||||||
|
doResolveUris: (Array<string>) => void,
|
||||||
fetchTopLevelComments: (string, number, number, number) => void,
|
fetchTopLevelComments: (string, number, number, number) => void,
|
||||||
fetchComment: (string) => void,
|
fetchComment: (string) => void,
|
||||||
resetComments: (string) => void,
|
resetComments: (string) => void,
|
||||||
|
@ -60,6 +62,7 @@ function CommentList(props: Props) {
|
||||||
uri,
|
uri,
|
||||||
pinnedComments,
|
pinnedComments,
|
||||||
topLevelComments,
|
topLevelComments,
|
||||||
|
resolvedComments,
|
||||||
topLevelTotalPages,
|
topLevelTotalPages,
|
||||||
claim,
|
claim,
|
||||||
claimIsMine,
|
claimIsMine,
|
||||||
|
@ -74,8 +77,9 @@ function CommentList(props: Props) {
|
||||||
othersReactsById,
|
othersReactsById,
|
||||||
activeChannelId,
|
activeChannelId,
|
||||||
settingsByChannelId,
|
settingsByChannelId,
|
||||||
fetchReacts,
|
|
||||||
commentsAreExpanded,
|
commentsAreExpanded,
|
||||||
|
fetchReacts,
|
||||||
|
doResolveUris,
|
||||||
fetchTopLevelComments,
|
fetchTopLevelComments,
|
||||||
fetchComment,
|
fetchComment,
|
||||||
resetComments,
|
resetComments,
|
||||||
|
@ -221,8 +225,16 @@ function CommentList(props: Props) {
|
||||||
}
|
}
|
||||||
}, [hasDefaultExpansion, isFetchingComments, moreBelow, page, readyToDisplayComments, topLevelTotalPages]);
|
}, [hasDefaultExpansion, isFetchingComments, moreBelow, page, readyToDisplayComments, topLevelTotalPages]);
|
||||||
|
|
||||||
const getCommentElems = (comments) => {
|
// Batch resolve comment channel urls
|
||||||
return comments.map((comment) => (
|
useEffect(() => {
|
||||||
|
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}
|
||||||
|
@ -247,22 +259,19 @@ 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}
|
icon={icon}
|
||||||
icon={icon}
|
iconSize={18}
|
||||||
iconSize={18}
|
onClick={() => changeSort(sortOption)}
|
||||||
onClick={() => changeSort(sortOption)}
|
className={classnames(`button-toggle`, {
|
||||||
className={classnames(`button-toggle`, {
|
'button-toggle--active': sort === sortOption,
|
||||||
'button-toggle--active': sort === sortOption,
|
})}
|
||||||
})}
|
/>
|
||||||
/>
|
);
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
|
@ -299,7 +308,7 @@ function CommentList(props: Props) {
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{readyToDisplayComments && pinnedComments && getCommentElems(pinnedComments)}
|
{readyToDisplayComments && pinnedComments && getCommentElems(pinnedComments)}
|
||||||
{readyToDisplayComments && topLevelComments && getCommentElems(topLevelComments)}
|
{readyToDisplayComments && resolvedComments && getCommentElems(resolvedComments)}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{!hasDefaultExpansion && (
|
{!hasDefaultExpansion && (
|
||||||
|
|
Loading…
Reference in a new issue
resolveComments = topLevelComments.filter()
might be a clearer choice to convey the intention, but that's minor.