mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
Adding config with initial
This commit is contained in:
@@ -8,3 +8,7 @@ export const setActiveTab = (tab) => (dispatch, getState) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const addExternalConfig = externalConfig => ({
|
||||
type: 'ADD_EXTERNAL_CONFIG',
|
||||
externalConfig
|
||||
});
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const ADD_EXTERNAL_CONFIG = 'ADD_EXTERNAL_CONFIG';
|
||||
@@ -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);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 (
|
||||
<div className={cn({[styles.inline]: inline, [styles.debug]: debug})}>
|
||||
{getSlotElements(fill, {config, ...rest})}
|
||||
{getSlotElements(fill, {...config, ...rest})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user