From 4b74c3312ff4b6f48d532d33696d76ddce5ede1e Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 24 Jul 2017 15:36:00 -0300 Subject: [PATCH 1/5] typo --- graph/loaders/comments.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graph/loaders/comments.js b/graph/loaders/comments.js index b0475d3ef..16d2101f7 100644 --- a/graph/loaders/comments.js +++ b/graph/loaders/comments.js @@ -445,12 +445,12 @@ const genRecentComments = (_, ids) => { }; /** - * genComments returns the comments by the id's. Only admins can see non-public comments. + * getComments returns the comments by the id's. Only admins can see non-public comments. * @param {Object} context graph context * @param {Array} ids the comment id's to fetch * @return {Promise} resolves to the comments */ -const genComments = ({user}, ids) => { +const getComments = ({user}, ids) => { let comments; if (user && user.can(SEARCH_OTHERS_COMMENTS)) { comments = CommentModel.find({ @@ -478,7 +478,7 @@ const genComments = ({user}, ids) => { */ module.exports = (context) => ({ Comments: { - get: new DataLoader((ids) => genComments(context, ids)), + get: new DataLoader((ids) => getComments(context, ids)), getByQuery: (query) => getCommentsByQuery(context, query), getCountByQuery: (query) => getCommentCountByQuery(context, query), countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', 3600, (ids) => getCountsByAssetID(context, ids)), From 36df7cb7842db4cc52e1433af796e01c79f015b0 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 24 Jul 2017 16:31:24 -0300 Subject: [PATCH 2/5] Extended Asset with comment --- .../src/components/Stream.js | 2 +- .../src/containers/Stream.js | 18 +++++++++--------- graph/resolvers/asset.js | 6 ++++++ graph/typeDefs.graphql | 3 +++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/client/coral-embed-stream/src/components/Stream.js b/client/coral-embed-stream/src/components/Stream.js index 2a1381862..e6e184dfa 100644 --- a/client/coral-embed-stream/src/components/Stream.js +++ b/client/coral-embed-stream/src/components/Stream.js @@ -81,7 +81,7 @@ class Stream extends React.Component { setActiveReplyBox, appendItemArray, commentClassNames, - root: {asset, asset: {comments, totalCommentCount}, comment, me}, + root: {asset, asset: {comment, comments, totalCommentCount}, me}, postComment, addNotification, editComment, diff --git a/client/coral-embed-stream/src/containers/Stream.js b/client/coral-embed-stream/src/containers/Stream.js index ea0676e51..804f3d37e 100644 --- a/client/coral-embed-stream/src/containers/Stream.js +++ b/client/coral-embed-stream/src/containers/Stream.js @@ -237,16 +237,16 @@ const slots = [ const fragments = { root: gql` fragment CoralEmbedStream_Stream_root on RootQuery { - comment(id: $commentId) @include(if: $hasComment) { - ...CoralEmbedStream_Stream_comment - ${nest(` - parent { - ...CoralEmbedStream_Stream_comment - ...nest - } - `, THREADING_LEVEL)} - } asset(id: $assetId, url: $assetUrl) { + comment(id: $commentId) @include(if: $hasComment) { + ...CoralEmbedStream_Stream_comment + ${nest(` + parent { + ...CoralEmbedStream_Stream_comment + ...nest + } + `, THREADING_LEVEL)} + } id title url diff --git a/graph/resolvers/asset.js b/graph/resolvers/asset.js index 86e102631..497ea0f9b 100644 --- a/graph/resolvers/asset.js +++ b/graph/resolvers/asset.js @@ -4,6 +4,12 @@ const Asset = { recentComments({id}, _, {loaders: {Comments}}) { return Comments.genRecentComments.load(id); }, + comment({id}, {id: commentId}, {loaders: {Comments}}) { + return Comments.getByQuery({ + asset_id: id, + ids: commentId + }).then((c) => c.nodes[0]); + }, comments({id}, {sort, limit, deep, excludeIgnored, tags}, {loaders: {Comments}}) { return Comments.getByQuery({ asset_id: id, diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index a154f9f90..999aea51c 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -580,6 +580,9 @@ type Asset { deep: Boolean, ): CommentConnection! + # A Comment from the Asset by comment's ID + comment(id: ID!): Comment + # The count of top level comments on the asset. commentCount(excludeIgnored: Boolean, tags: [String!]): Int From a036a051cb8a2eb3f6f9ce20ecd054c6138b90bf Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 24 Jul 2017 16:40:08 -0300 Subject: [PATCH 3/5] Using async await --- graph/resolvers/asset.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/graph/resolvers/asset.js b/graph/resolvers/asset.js index 497ea0f9b..da9114c6a 100644 --- a/graph/resolvers/asset.js +++ b/graph/resolvers/asset.js @@ -4,11 +4,13 @@ const Asset = { recentComments({id}, _, {loaders: {Comments}}) { return Comments.genRecentComments.load(id); }, - comment({id}, {id: commentId}, {loaders: {Comments}}) { - return Comments.getByQuery({ + async comment({id}, {id: commentId}, {loaders: {Comments}}) { + const comments = await Comments.getByQuery({ asset_id: id, ids: commentId - }).then((c) => c.nodes[0]); + }); + + return comments.nodes[0]; }, comments({id}, {sort, limit, deep, excludeIgnored, tags}, {loaders: {Comments}}) { return Comments.getByQuery({ From f10d1a9f0d3704be4a3e8ced5595aaccbf723cc9 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 25 Jul 2017 19:11:11 +0700 Subject: [PATCH 4/5] Adapt auto scroll when loading a permalinked comment --- client/coral-embed-stream/src/containers/Embed.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/coral-embed-stream/src/containers/Embed.js b/client/coral-embed-stream/src/containers/Embed.js index a31dbe911..06646a6c2 100644 --- a/client/coral-embed-stream/src/containers/Embed.js +++ b/client/coral-embed-stream/src/containers/Embed.js @@ -3,6 +3,7 @@ import {compose, gql} from 'react-apollo'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; import isEqual from 'lodash/isEqual'; +import get from 'lodash/get'; import branch from 'recompose/branch'; import renderComponent from 'recompose/renderComponent'; @@ -91,7 +92,7 @@ class EmbedContainer extends React.Component { } componentDidUpdate(prevProps) { - if (!prevProps.root.comment && this.props.root.comment) { + if (!get(prevProps, 'root.asset.comment') && get(this.props, 'root.asset.comment')) { // Scroll to a permalinked comment if one is in the URL once the page is done rendering. setTimeout(() => pym.scrollParentToChildEl('talk-embed-stream-container'), 0); From ef759e068bcf1a6e12454c0b469c7f4e650c092c Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 25 Jul 2017 19:14:03 +0700 Subject: [PATCH 5/5] Adapt query helpers --- client/coral-embed-stream/src/graphql/utils.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client/coral-embed-stream/src/graphql/utils.js b/client/coral-embed-stream/src/graphql/utils.js index 4f51b0ae2..1030a3547 100644 --- a/client/coral-embed-stream/src/graphql/utils.js +++ b/client/coral-embed-stream/src/graphql/utils.js @@ -12,8 +12,8 @@ function determineCommentDepth(comment) { } function applyToCommentsOrigin(root, callback) { - if (root.comment) { - let comment = root.comment; + if (root.asset.comment) { + let comment = root.asset.comment; for (let depth = 0; depth <= determineCommentDepth(comment); depth++) { let changes = {$apply: (node) => node ? callback(node) : node}; for (let i = 0; i < depth; i++) { @@ -24,7 +24,10 @@ function applyToCommentsOrigin(root, callback) { return { ...root, - comment, + asset: { + ...root.asset, + comment, + }, }; } return update(root, { @@ -135,8 +138,8 @@ export function findCommentInEmbedQuery(root, callbackOrId) { if (typeof callbackOrId === 'string') { callback = (node) => node.id === callbackOrId; } - if (root.comment) { - return findComment([getTopLevelParent(root.comment)], callback); + if (root.asset.comment) { + return findComment([getTopLevelParent(root.asset.comment)], callback); } if (!root.asset.comments) { return false;