From bf23fc29740ba1f70cd15dbbde9acfef555cbf2e Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 28 Feb 2017 12:02:51 -0500 Subject: [PATCH] Moving comment id into query. --- client/coral-embed-stream/src/Embed.js | 3 ++- client/coral-embed/index.js | 17 +++++++++++------ .../graphql/queries/commentQuery.graphql | 13 +++++++++++++ client/coral-framework/graphql/queries/index.js | 9 +++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 client/coral-framework/graphql/queries/commentQuery.graphql diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index ac9c09eac..b0f5d5c5a 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -12,7 +12,7 @@ const {logout, showSignInDialog, requestConfirmEmail} = authActions; const {addNotification, clearNotification} = notificationActions; const {fetchAssetSuccess} = assetActions; -import {queryStream} from 'coral-framework/graphql/queries'; +import {queryStream, commentQuery} from 'coral-framework/graphql/queries'; import {postComment, postFlag, postLike, postDontAgree, deleteAction} from 'coral-framework/graphql/mutations'; import {editName} from 'coral-framework/actions/user'; import {updateCountCache} from 'coral-framework/actions/asset'; @@ -251,5 +251,6 @@ export default compose( postLike, postDontAgree, deleteAction, + commentQuery, queryStream )(Embed); diff --git a/client/coral-embed/index.js b/client/coral-embed/index.js index 4a7e753ca..9f3b23aaf 100644 --- a/client/coral-embed/index.js +++ b/client/coral-embed/index.js @@ -58,10 +58,11 @@ // ensure el has an id, as pym can't directly accept the HTMLElement if ( ! el.id) {el.id = '_' + String(Math.random());} - var asset = opts.asset || window.location; + var asset = opts.asset || window.location.href.split('#')[0]; + var comment = window.location.hash.slice(1); var pymParent = new pym.Parent( el.id, - buildStreamIframeUrl(opts.talk, asset), + buildStreamIframeUrl(opts.talk, asset, comment), { title: opts.title, asset_url: asset, @@ -76,14 +77,18 @@ return Coral; // build the URL to load in the pym iframe - function buildStreamIframeUrl(talkBaseUrl, asset) { - var iframeUrl = [ + function buildStreamIframeUrl(talkBaseUrl, asset, comment) { + var iframeArray = [ talkBaseUrl, (talkBaseUrl.match(/\/$/) ? '' : '/'), // make sure no double-'/' if opts.talk already ends with '/' 'embed/stream?asset_url=', encodeURIComponent(asset) - ].join(''); - return iframeUrl; + ]; + + if (comment) { + iframeArray.push(`&comment_id=${comment}`); + } + return iframeArray.join(''); } // Set up postMessage listeners/handlers on the pymParent diff --git a/client/coral-framework/graphql/queries/commentQuery.graphql b/client/coral-framework/graphql/queries/commentQuery.graphql new file mode 100644 index 000000000..83f92b8f5 --- /dev/null +++ b/client/coral-framework/graphql/queries/commentQuery.graphql @@ -0,0 +1,13 @@ +#import "../fragments/commentView.graphql" + +query commentQuery($id: ID!) { + comment(id: $id) { + ...commentView + parent { + ...commentView + replies { + ...commentView + } + } + } +} diff --git a/client/coral-framework/graphql/queries/index.js b/client/coral-framework/graphql/queries/index.js index c993dfb6a..8d61c9f8b 100644 --- a/client/coral-framework/graphql/queries/index.js +++ b/client/coral-framework/graphql/queries/index.js @@ -2,6 +2,7 @@ import {graphql} from 'react-apollo'; import STREAM_QUERY from './streamQuery.graphql'; import LOAD_MORE from './loadMore.graphql'; import GET_COUNTS from './getCounts.graphql'; +import COMMENT_QUERY from './commentQuery.graphql'; import MY_COMMENT_HISTORY from './myCommentHistory.graphql'; function getQueryVariable(variable) { @@ -97,4 +98,12 @@ export const queryStream = graphql(STREAM_QUERY, { }) }); +export const commentQuery = graphql(COMMENT_QUERY, { + options: () => ({ + variables: { + id: getQueryVariable('comment_id') + } + }) +}); + export const myCommentHistory = graphql(MY_COMMENT_HISTORY, {});