import React, { PropTypes, Component } from 'react'; class CommentItem extends Component{ constructor() { super(); ['showReply', 'replyCancelCallback', 'replySuccessCallback', 'showEdit', 'editCancelCallback', 'editSuccessCallback'].forEach(methodName => {this[methodName] = this[methodName].bind(this)}); this.state = { showReply: false, showEdit: false }; } showReply(event) { event.preventDefault(); this.setState({showReply: true}); } replyCancelCallback(event) { event.preventDefault(); this.setState({showReply: false}); } replySuccessCallback() { this.setState({showReply: false}); } showEdit(event) { event.preventDefault(); this.setState({showEdit: true}); } editCancelCallback(event) { event.preventDefault(); this.setState({showEdit: false}); } editSuccessCallback() { this.setState({showEdit: false}); } renderComment() { const htmlBody = {__html: this.props.comment.htmlBody}; return (
Reply
) } renderReply() { ({CommentNew} = Telescope.components); return (
) } renderEdit() { ({CommentEdit} = Telescope.components); return ( ) } render() { ({UserAvatar} = Telescope.components); const comment = this.props.comment; return (
{moment(comment.postedAt).fromNow()}
{Users.can.edit(this.props.currentUser, this.props.comment) ? Edit : null}
{this.state.showEdit ? this.renderEdit() : this.renderComment()}
{this.state.showReply ? this.renderReply() : null}
) } } CommentItem.propTypes = { comment: React.PropTypes.object.isRequired, // the current comment currentUser: React.PropTypes.object, // the current user } module.exports = CommentItem;