import React, {Component} from 'react'; import {compose} from 'react-apollo'; import {connect} from 'react-redux'; import isEqual from 'lodash/isEqual'; import {TabBar, Tab, TabContent, Spinner} from '../../coral-ui'; const {logout, showSignInDialog, requestConfirmEmail} = authActions; const {addNotification, clearNotification} = notificationActions; const {fetchAssetSuccess} = assetActions; import {queryStream} from 'coral-framework/graphql/queries'; import {postComment, postAction, deleteAction} from 'coral-framework/graphql/mutations'; import {Notification, notificationActions, authActions, assetActions, pym} from 'coral-framework'; import Stream from './Stream'; import InfoBox from 'coral-plugin-infobox/InfoBox'; import Count from 'coral-plugin-comment-count/CommentCount'; import CommentBox from 'coral-plugin-commentbox/CommentBox'; import UserBox from '../../coral-sign-in/components/UserBox'; import SignInContainer from '../../coral-sign-in/containers/SignInContainer'; import ChangeDisplayNameContainer from '../../coral-sign-in/containers/ChangeDisplayNameContainer'; import SuspendedAccount from '../../coral-framework/components/SuspendedAccount'; import SettingsContainer from '../../coral-settings/containers/SettingsContainer'; import RestrictedContent from '../../coral-framework/components/RestrictedContent'; import ConfigureStreamContainer from '../../coral-configure/containers/ConfigureStreamContainer'; class Embed extends Component { constructor (props) { super(props); this.state = { activeTab: 0, showSignInDialog: false }; this.changeTab = this.changeTab.bind(this); } changeTab (tab) { this.setState({ activeTab: tab }); } static propTypes = { data: React.PropTypes.shape({ loading: React.PropTypes.bool, error: React.PropTypes.object }).isRequired } componentDidMount () { 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); }); } componentWillReceiveProps (nextProps) { const {loadAsset} = this.props; if(!isEqual(nextProps.data.asset, this.props.data.asset)) { loadAsset(nextProps.data.asset); } } render () { const {activeTab} = this.state; const {closedAt} = this.props.asset; const {loading, asset, refetch} = this.props.data; const {loggedIn, isAdmin, user, showSignInDialog, signInOffset} = this.props.auth; const openStream = closedAt === null; const expandForLogin = showSignInDialog ? { minHeight: document.body.scrollHeight + 200 } : {}; return
{ loading ? :
Settings Configure Stream {loggedIn && user && } { openStream ?
}> { user ? : null }
:

{asset.settings.closedMessage}

} {!loggedIn && } {loggedIn && user && }
}
; } } const mapStateToProps = state => ({ notification: state.notification.toJS(), auth: state.auth.toJS(), userData: state.user.toJS(), asset: state.asset.toJS() }); const mapDispatchToProps = dispatch => ({ requestConfirmEmail: () => dispatch(requestConfirmEmail()), loadAsset: (asset) => dispatch(fetchAssetSuccess(asset)), addNotification: (type, text) => dispatch(addNotification(type, text)), clearNotification: () => dispatch(clearNotification()), showSignInDialog: (offset) => dispatch(showSignInDialog(offset)), logout: () => dispatch(logout()), dispatch: d => dispatch(d) }); export default compose( connect(mapStateToProps, mapDispatchToProps), postComment, postAction, deleteAction, queryStream )(Embed);