Fix load more replies

This commit is contained in:
Chi Vinh Le
2017-12-08 23:14:40 +01:00
parent c0d01e55e1
commit 71f0200557
2 changed files with 10 additions and 5 deletions
@@ -142,17 +142,21 @@ export function findCommentWithId(nodes, id) {
}
export function findCommentInEmbedQuery(root, callbackOrId) {
return findCommentInAsset(root.asset, callbackOrId);
}
export function findCommentInAsset(asset, callbackOrId) {
let callback = callbackOrId;
if (typeof callbackOrId === 'string') {
callback = (node) => node.id === callbackOrId;
}
if (root.asset.comment) {
return findComment([getTopLevelParent(root.asset.comment)], callback);
if (asset.comment) {
return findComment([getTopLevelParent(asset.comment)], callback);
}
if (!root.asset.comments) {
if (!asset.comments) {
return false;
}
return findComment(root.asset.comments.nodes, callback);
return findComment(asset.comments.nodes, callback);
}
function findAndInsertFetchedComments(parent, comments, parent_id) {
@@ -19,6 +19,7 @@ import {Spinner} from 'coral-ui';
import {can} from 'coral-framework/services/perms';
import {
findCommentInEmbedQuery,
findCommentInAsset,
insertCommentIntoEmbedQuery,
removeCommentFromEmbedQuery,
insertFetchedCommentsIntoEmbedQuery,
@@ -108,7 +109,7 @@ class StreamContainer extends React.Component {
}
loadNewReplies = (parent_id) => {
const comment = findCommentInEmbedQuery(this.props.root, parent_id);
const comment = findCommentInAsset(this.props.asset, parent_id);
return this.props.data.fetchMore({
query: LOAD_MORE_QUERY,