diff --git a/client/coral-framework/actions/config.js b/client/coral-embed-stream/src/actions/config.js similarity index 100% rename from client/coral-framework/actions/config.js rename to client/coral-embed-stream/src/actions/config.js diff --git a/client/coral-embed-stream/src/actions/embed.js b/client/coral-embed-stream/src/actions/embed.js index 863494c68..c0eb7d844 100644 --- a/client/coral-embed-stream/src/actions/embed.js +++ b/client/coral-embed-stream/src/actions/embed.js @@ -8,3 +8,7 @@ export const setActiveTab = (tab) => (dispatch, getState) => { } }; +export const addExternalConfig = externalConfig => ({ + type: 'ADD_EXTERNAL_CONFIG', + externalConfig +}); diff --git a/client/coral-embed-stream/src/constants/config.js b/client/coral-embed-stream/src/constants/config.js new file mode 100644 index 000000000..5821316c5 --- /dev/null +++ b/client/coral-embed-stream/src/constants/config.js @@ -0,0 +1 @@ +export const ADD_EXTERNAL_CONFIG = 'ADD_EXTERNAL_CONFIG'; diff --git a/client/coral-embed-stream/src/containers/Embed.js b/client/coral-embed-stream/src/containers/Embed.js index 5b324b35b..75d5dcbaf 100644 --- a/client/coral-embed-stream/src/containers/Embed.js +++ b/client/coral-embed-stream/src/containers/Embed.js @@ -13,7 +13,6 @@ import Stream from './Stream'; import Embed from '../components/Embed'; import {setActiveTab} from '../actions/embed'; -import {addExternalConfig} from 'coral-framework/actions/config'; import {setCommentCountCache, viewAllComments} from '../actions/stream'; import {getDefinitionName, separateDataAndRoot} from 'coral-framework/utils'; @@ -21,17 +20,6 @@ const {logout, checkLogin} = authActions; const {fetchAssetSuccess} = assetActions; class EmbedContainer extends React.Component { - componentDidMount() { - pym.sendMessage('childReady'); - - pym.onMessage('config', config => { - this.props.addExternalConfig(JSON.parse(config)); - }); - } - - componentWillUnmount() { - pym.remove(); - } componentWillReceiveProps(nextProps) { if (this.props.root.me && !nextProps.root.me) { @@ -114,7 +102,6 @@ const mapDispatchToProps = dispatch => checkLogin, setActiveTab, viewAllComments, - addExternalConfig, fetchAssetSuccess, setCommentCountCache }, @@ -123,6 +110,6 @@ const mapDispatchToProps = dispatch => export default compose( connect(mapStateToProps, mapDispatchToProps), - branch(props => !props.auth.checkedInitialLogin, renderComponent(Spinner)), + branch(props => !props.auth.checkedInitialLogin && props.config, renderComponent(Spinner)), withQuery )(EmbedContainer); diff --git a/client/coral-embed-stream/src/index.js b/client/coral-embed-stream/src/index.js index 2fd1e2731..52a585fb2 100644 --- a/client/coral-embed-stream/src/index.js +++ b/client/coral-embed-stream/src/index.js @@ -4,10 +4,12 @@ import {ApolloProvider} from 'react-apollo'; import {client} from 'coral-framework/services/client'; import {checkLogin} from 'coral-framework/actions/auth'; +import {addExternalConfig} from 'coral-embed-stream/src/actions/config'; import reducers from './reducers'; import localStore, {injectReducers} from 'coral-framework/services/store'; import AppRouter from './AppRouter'; +import {pym} from 'coral-framework'; injectReducers(reducers); @@ -16,6 +18,12 @@ const store = (window.opener && window.opener.coralStore) ? window.opener.coralS // Don't run this in the popup. if (store === localStore) { store.dispatch(checkLogin()); + + pym.sendMessage('getConfig'); + + pym.onMessage('config', config => { + store.dispatch(addExternalConfig(JSON.parse(config))); + }); } render( diff --git a/client/coral-framework/reducers/config.js b/client/coral-embed-stream/src/reducers/config.js similarity index 100% rename from client/coral-framework/reducers/config.js rename to client/coral-embed-stream/src/reducers/config.js diff --git a/client/coral-embed-stream/src/reducers/index.js b/client/coral-embed-stream/src/reducers/index.js index a9049fc14..590b87eea 100644 --- a/client/coral-embed-stream/src/reducers/index.js +++ b/client/coral-embed-stream/src/reducers/index.js @@ -1,7 +1,9 @@ -import stream from './stream'; import embed from './embed'; +import config from './config'; +import stream from './stream'; export default { - stream, embed, + stream, + config }; diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index cc2612376..570a63aed 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -46,20 +46,19 @@ function buildStreamIframeUrl(talkBaseUrl, query) { // e.g. to resize the iframe, and navigate the host page function configurePymParent(pymParent, opts) { let notificationOffset = 200; - let DOMReady = false; let cachedHeight; const snackbar = document.createElement('div'); - // Sets DOMReady - function completed() { - DOMReady = true; - } - // Sends config to pymChild function sendConfig(config) { pymParent.sendMessage('config', JSON.stringify(config)); } + // Sends config to the child + pymParent.onMessage('getConfig', function() { + sendConfig(opts || {}); + }); + snackbar.id = 'coral-notif'; for (let key in snackbarStyles) { @@ -121,31 +120,6 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('position', position); }); - // Sends config to the child - pymParent.onMessage('getConfig', function() { - sendConfig(opts || {}); - }); - - document.addEventListener('DOMContentLoaded', completed, false); - - // A fallback to window.onload, that will always work - window.addEventListener('load', completed, false); - - // Tell child when parent's DOMContentLoaded - pymParent.onMessage('childReady', function() { - const interval = setInterval(function() { - if (DOMReady) { - window.clearInterval(interval); - - // DOMContentLoaded is ready - pymParent.sendMessage('DOMContentLoaded'); - - // Sending the config to the child - sendConfig(opts || {}); - } - }, 100); - }); - // When end-user clicks link in iframe, open it in parent context pymParent.onMessage('navigate', function(url) { window.open(url, '_blank').focus(); diff --git a/client/coral-framework/components/Slot.js b/client/coral-framework/components/Slot.js index eac90c6df..68b5e9964 100644 --- a/client/coral-framework/components/Slot.js +++ b/client/coral-framework/components/Slot.js @@ -4,10 +4,10 @@ import styles from './Slot.css'; import {connect} from 'react-redux'; import {getSlotElements} from 'coral-framework/helpers/plugins'; -function Slot ({fill, inline = false, plugin_config: {debug, config}, ...rest}) { +function Slot ({fill, inline = false, plugin_config: {debug, ...config}, ...rest}) { return (
- {getSlotElements(fill, {config, ...rest})} + {getSlotElements(fill, {...config, ...rest})}
); } diff --git a/client/coral-framework/constants/config.js b/client/coral-framework/constants/config.js deleted file mode 100644 index a7b2fa8fb..000000000 --- a/client/coral-framework/constants/config.js +++ /dev/null @@ -1,13 +0,0 @@ -export const UPDATE_CONFIG_REQUEST = 'UPDATE_CONFIG_REQUEST'; -export const UPDATE_CONFIG_SUCCESS = 'UPDATE_CONFIG_SUCCESS'; -export const UPDATE_CONFIG_FAILURE = 'UPDATE_CONFIG_FAILURE'; - -export const UPDATE_CONFIG = 'UPDATE_CONFIG'; - -export const OPEN_COMMENTS = 'OPEN_COMMENTS'; -export const CLOSE_COMMENTS = 'CLOSE_COMMENTS'; -export const ADD_ITEM = 'ADD_ITEM'; - -// TODO: Deprecate old constants - -export const ADD_EXTERNAL_CONFIG = 'ADD_EXTERNAL_CONFIG'; diff --git a/client/coral-framework/reducers/index.js b/client/coral-framework/reducers/index.js index 7067bfb55..d5b66bbae 100644 --- a/client/coral-framework/reducers/index.js +++ b/client/coral-framework/reducers/index.js @@ -1,7 +1,6 @@ import auth from './auth'; import user from './user'; import asset from './asset'; -import config from './config'; import {reducer as commentBox} from '../../coral-plugin-commentbox'; import {pluginReducers} from '../helpers/plugins'; @@ -9,7 +8,6 @@ export default { auth, user, asset, - config, commentBox, ...pluginReducers };