import React, {Component, PropTypes} from 'react'; import Pym from 'pym.js'; import {connect} from 'react-redux'; import { itemActions, Notification, notificationActions, authActions, configActions } from '../../coral-framework'; import CommentBox from '../../coral-plugin-commentbox/CommentBox'; import InfoBox from '../../coral-plugin-infobox/InfoBox'; import Content from '../../coral-plugin-commentcontent/CommentContent'; import PubDate from '../../coral-plugin-pubdate/PubDate'; import Count from '../../coral-plugin-comment-count/CommentCount'; import AuthorName from '../../coral-plugin-author-name/AuthorName'; import {ReplyBox, ReplyButton} from '../../coral-plugin-replies'; import FlagButton from '../../coral-plugin-flags/FlagButton'; import LikeButton from '../../coral-plugin-likes/LikeButton'; import PermalinkButton from '../../coral-plugin-permalinks/PermalinkButton'; import SignInContainer from '../../coral-sign-in/containers/SignInContainer'; import UserBox from '../../coral-sign-in/components/UserBox'; import {TabBar, Tab, TabContent, Spinner} from '../../coral-ui'; import SettingsContainer from '../../coral-settings/containers/SettingsContainer'; import RestrictedContent from '../../coral-framework/components/RestrictedContent'; import SuspendedAccount from '../../coral-framework/components/SuspendedAccount'; import CloseCommentsInfo from '../../coral-framework/components/CloseCommentsInfo'; const {addItem, updateItem, postItem, getStream, postAction, deleteAction, appendItemArray} = itemActions; const {addNotification, clearNotification} = notificationActions; const {logout, showSignInDialog} = authActions; const {updateOpenStatus} = configActions; class CommentStream extends Component { constructor (props) { super(props); this.state = { activeTab: 0 }; this.changeTab = this.changeTab.bind(this); this.toggleStatus = this.toggleStatus.bind(this); } changeTab (tab) { this.setState({ activeTab: tab }); } toggleStatus () { this.props.updateStatus(this.props.config.status === 'open' ? 'closed' : 'open'); } static propTypes = { items: PropTypes.object.isRequired, addItem: PropTypes.func.isRequired, updateItem: PropTypes.func.isRequired } componentDidMount () { // Set up messaging between embedded Iframe an parent component this.pym = new Pym.Child({polling: 100}); const path = /https?\:\/\/([^?#]+)/.exec(this.pym.parentUrl); this.props.getStream(path[1] || window.location); this.path = path; this.pym.sendMessage('childReady'); } render () { const rootItemId = this.props.items.assets && Object.keys(this.props.items.assets)[0]; const rootItem = this.props.items.assets && this.props.items.assets[rootItemId]; const {actions, users, comments} = this.props.items; const {loggedIn, user, showSignInDialog} = this.props.auth; const {status} = this.props.config; const {activeTab} = this.state; const banned = (this.props.userData.status === 'banned'); return
{ rootItem ?
Settings Configure Stream {loggedIn && } { status === 'open' ?
}>
:

Comments are closed for this thread.

} {!loggedIn && } { rootItem.comments && rootItem.comments.map((commentId) => { const comment = comments[commentId]; return

{ comment.children && comment.children.map((replyId) => { let reply = this.props.items.comments[replyId]; return

; }) }
; }) }

{status === 'open' ? 'Close' : 'Open'} Comment Stream

: }
; } } const mapStateToProps = state => ({ config: state.config.toJS(), items: state.items.toJS(), notification: state.notification.toJS(), auth: state.auth.toJS(), userData: state.user.toJS() }); const mapDispatchToProps = (dispatch) => ({ addItem: (item, itemType) => dispatch(addItem(item, itemType)), updateItem: (id, property, value, itemType) => dispatch(updateItem(id, property, value, itemType)), postItem: (data, type, id) => dispatch(postItem(data, type, id)), getStream: (rootId) => dispatch(getStream(rootId)), addNotification: (type, text) => dispatch(addNotification(type, text)), clearNotification: () => dispatch(clearNotification()), showSignInDialog: () => dispatch(showSignInDialog()), postAction: (item, action, user, itemType) => dispatch(postAction(item, action, user, itemType)), deleteAction: (item, action, user, itemType) => dispatch(deleteAction(item, action, user, itemType)), appendItemArray: (item, property, value, addToFront, itemType) => dispatch(appendItemArray(item, property, value, addToFront, itemType)), handleSignInDialog: () => dispatch(authActions.showSignInDialog()), logout: () => dispatch(logout()), updateStatus: status => dispatch(updateOpenStatus(status)) }); export default connect(mapStateToProps, mapDispatchToProps)(CommentStream);