import React, {Component, PropTypes} from 'react'; import { itemActions, Notification, notificationActions, authActions } from '../../coral-framework'; import {connect} from 'react-redux'; import CommentBox from '../../coral-plugin-commentbox/CommentBox'; 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 Pym from 'pym.js'; import FlagButton from '../../coral-plugin-flags/FlagButton'; import LikeButton from '../../coral-plugin-likes/LikeButton'; import PermalinkButton from '../../coral-plugin-permalinks/PermalinkButton'; const {addItem, updateItem, postItem, getStream, postAction, deleteAction, appendItemArray} = itemActions; const {addNotification, clearNotification} = notificationActions; const {setLoggedInUser} = authActions; const mapStateToProps = (state) => { return { config: state.config.toJS(), items: state.items.toJS(), notification: state.notification.toJS(), auth: state.auth.toJS() }; }; const mapDispatchToProps = (dispatch) => { return { addItem: (item, itemType) => { return dispatch(addItem(item, itemType)); }, updateItem: (id, property, value, itemType) => { return dispatch(updateItem(id, property, value, itemType)); }, postItem: (data, type, id) => { return dispatch(postItem(data, type, id)); }, getStream: (rootId) => { return dispatch(getStream(rootId)); }, addNotification: (type, text) => { return dispatch(addNotification(type, text)); }, clearNotification: () => { return dispatch(clearNotification()); }, setLoggedInUser: (user_id) => { return dispatch(setLoggedInUser(user_id)); }, postAction: (item, action, user, itemType) => { return dispatch(postAction(item, action, user, itemType)); }, deleteAction: (item, action, user, itemType) => { return dispatch(deleteAction(item, action, user, itemType)); }, appendItemArray: (item, property, value, addToFront, itemType) => { return dispatch(appendItemArray(item, property, value, addToFront, itemType)); } }; }; class CommentStream extends Component { static propTypes = { items: PropTypes.object.isRequired, addItem: PropTypes.func.isRequired, updateItem: PropTypes.func.isRequired } componentDidMount () { // Set up messaging between embedded Iframe an parent component // Using recommended Pym init code which violates .eslint standards new Pym.Child({polling: 500}); this.props.getStream('assetTest'); } render () { if (Object.keys(this.props.items).length === 0) { // Loading mock asset this.props.postItem({ comments: [], url: 'http://coralproject.net' }, 'asset', 'assetTest'); // Loading mock user this.props.postItem({name: 'Ban Ki-Moon'}, 'user', 'user_8989') .then((id) => { this.props.setLoggedInUser(id); }); } // TODO: Replace teststream id with id from params const rootItemId = 'assetTest'; const rootItem = this.props.items.assets && this.props.items.assets[rootItemId]; return
{ rootItem ?
{ rootItem.comments.map((commentId) => { const comment = this.props.items.comments[commentId]; return

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

; }) }
; }) }
: 'Loading' }
; } } export default connect(mapStateToProps, mapDispatchToProps)(CommentStream);