Batch resolve replies
This commit is contained in:
parent
cafefb2a33
commit
620de2e6b7
2 changed files with 43 additions and 13 deletions
|
@ -1,15 +1,29 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { makeSelectClaimIsMine, selectMyChannelClaims } from 'lbry-redux';
|
import { makeSelectClaimIsMine, selectMyChannelClaims, makeSelectClaimForUri, doResolveUris } 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) => {
|
||||||
fetchedReplies: makeSelectRepliesForParentId(props.parentId)(state),
|
const 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,
|
userCanComment: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
|
||||||
myChannels: selectMyChannelClaims(state),
|
myChannels: selectMyChannelClaims(state),
|
||||||
isFetchingByParentId: selectIsFetchingCommentsByParentId(state),
|
isFetchingByParentId: selectIsFetchingCommentsByParentId(state),
|
||||||
});
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default connect(select)(CommentsReplies);
|
const perform = (dispatch) => ({ doResolveUris: (uris) => dispatch(doResolveUris(uris, true)) });
|
||||||
|
|
||||||
|
export default connect(select, perform)(CommentsReplies);
|
||||||
|
|
|
@ -6,7 +6,8 @@ import React from 'react';
|
||||||
import Spinner from 'component/spinner';
|
import Spinner from 'component/spinner';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
fetchedReplies: Array<any>,
|
fetchedReplies: Array<Comment>,
|
||||||
|
resolvedReplies: Array<Comment>,
|
||||||
uri: string,
|
uri: string,
|
||||||
parentId: string,
|
parentId: string,
|
||||||
claimIsMine: boolean,
|
claimIsMine: boolean,
|
||||||
|
@ -18,6 +19,7 @@ type Props = {
|
||||||
isFetchingByParentId: { [string]: boolean },
|
isFetchingByParentId: { [string]: boolean },
|
||||||
hasMore: boolean,
|
hasMore: boolean,
|
||||||
supportDisabled: boolean,
|
supportDisabled: boolean,
|
||||||
|
doResolveUris: (Array<string>) => void,
|
||||||
onShowMore?: () => void,
|
onShowMore?: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ function CommentsReplies(props: Props) {
|
||||||
uri,
|
uri,
|
||||||
parentId,
|
parentId,
|
||||||
fetchedReplies,
|
fetchedReplies,
|
||||||
|
resolvedReplies,
|
||||||
claimIsMine,
|
claimIsMine,
|
||||||
myChannels,
|
myChannels,
|
||||||
linkedCommentId,
|
linkedCommentId,
|
||||||
|
@ -35,10 +38,22 @@ function CommentsReplies(props: Props) {
|
||||||
isFetchingByParentId,
|
isFetchingByParentId,
|
||||||
hasMore,
|
hasMore,
|
||||||
supportDisabled,
|
supportDisabled,
|
||||||
|
doResolveUris,
|
||||||
onShowMore,
|
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
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!fetchedReplies) return;
|
||||||
|
|
||||||
|
const urisToResolve = [];
|
||||||
|
fetchedReplies.map(({ channel_url }) => channel_url !== undefined && urisToResolve.push(channel_url));
|
||||||
|
|
||||||
|
if (urisToResolve.length > 0) doResolveUris(urisToResolve);
|
||||||
|
}, [fetchedReplies, doResolveUris]);
|
||||||
|
|
||||||
return !numDirectReplies ? null : (
|
return !numDirectReplies ? null : (
|
||||||
<div className="comment__replies-container">
|
<div className="comment__replies-container">
|
||||||
|
@ -56,8 +71,9 @@ function CommentsReplies(props: Props) {
|
||||||
<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">
|
||||||
{fetchedReplies &&
|
{!isResolvingReplies &&
|
||||||
fetchedReplies.map((comment) => (
|
resolvedReplies.length > 0 &&
|
||||||
|
resolvedReplies.map((comment) => (
|
||||||
<Comment
|
<Comment
|
||||||
threadDepth={threadDepth}
|
threadDepth={threadDepth}
|
||||||
uri={uri}
|
uri={uri}
|
||||||
|
@ -96,7 +112,7 @@ function CommentsReplies(props: Props) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{isFetchingByParentId[parentId] && (
|
{(isFetchingByParentId[parentId] || isResolvingReplies) && (
|
||||||
<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" />
|
||||||
|
|
Loading…
Reference in a new issue