From 58e50b42422676ef8a99a269e6df0f96c2030b47 Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 24 Jan 2017 12:51:52 -0500 Subject: [PATCH] Fixing permalinks and moving Pym to a seperate file. --- client/coral-embed-stream/src/Embed.js | 39 ++++++++++--------- client/coral-embed-stream/src/Pym.js | 3 ++ .../src/graphql/queries/index.js | 5 +-- 3 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 client/coral-embed-stream/src/Pym.js diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index cf336256c..caf71990d 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -1,6 +1,6 @@ import React, {Component, PropTypes} from 'react'; -// import Pym from 'pym.js'; +import pym from './Pym'; import {compose} from 'react-apollo'; import {connect} from 'react-redux'; @@ -71,24 +71,25 @@ class Embed extends Component { // this.props.getStream(path || window.location); // this.path = window.location.href.split('#')[0]; // - // this.pym.sendMessage('childReady'); - // - // this.pym.onMessage('DOMContentLoaded', hash => { - // const commentId = hash.replace('#', 'c_'); - // let count = 0; - // const interval = setInterval(() => { - // if (document.getElementById(commentId)) { - // window.clearInterval(interval); - // this.pym.scrollParentToChildEl(commentId); - // } - // - // if (++count > 100) { // ~10 seconds - // // give up waiting for the comments to load. - // // it would be weird for the page to jump after that long. - // window.clearInterval(interval); - // } - // }, 100); - // }); + + pym.sendMessage('childReady'); + + pym.onMessage('DOMContentLoaded', hash => { + const commentId = hash.replace('#', 'c_'); + let count = 0; + const interval = setInterval(() => { + if (document.getElementById(commentId)) { + window.clearInterval(interval); + pym.scrollParentToChildEl(commentId); + } + + if (++count > 100) { // ~10 seconds + // give up waiting for the comments to load. + // it would be weird for the page to jump after that long. + window.clearInterval(interval); + } + }, 100); + }); } diff --git a/client/coral-embed-stream/src/Pym.js b/client/coral-embed-stream/src/Pym.js new file mode 100644 index 000000000..8e9073e2c --- /dev/null +++ b/client/coral-embed-stream/src/Pym.js @@ -0,0 +1,3 @@ +import Pym from 'pym.js'; + +export default new Pym.Child({polling: 100}); diff --git a/client/coral-embed-stream/src/graphql/queries/index.js b/client/coral-embed-stream/src/graphql/queries/index.js index ecf875aaa..41ae07116 100644 --- a/client/coral-embed-stream/src/graphql/queries/index.js +++ b/client/coral-embed-stream/src/graphql/queries/index.js @@ -1,9 +1,8 @@ import {graphql} from 'react-apollo'; import STREAM_QUERY from './streamQuery.graphql'; -import Pym from 'pym.js'; +import pym from '../../Pym'; -const pym = new Pym.Child({polling: 100}); -let url = pym.parentUrl || 'http://localhost:3000/'; +let url = pym.parentUrl.split('#')[0] || 'http://localhost:3000/'; export const queryStream = graphql(STREAM_QUERY, { options: {variables: {asset_url: url}}