Vulcan/packages/nova-components/lib/comments/list/CommentItem.jsx
2016-02-18 21:39:33 +09:00

93 lines
No EOL
1.9 KiB
JavaScript

const CommentItem = React.createClass({
propTypes: {
comment: React.PropTypes.object.isRequired, // the current comment
currentUser: React.PropTypes.object, // the current user
},
getInitialState() {
return {
showReply: false,
showEdit: false
};
},
showReply(event) {
event.preventDefault();
this.setState({showReply: true});
},
cancelReply(event) {
event.preventDefault();
this.setState({showReply: false});
},
replyCallback() {
this.setState({showReply: false});
},
showEdit(event) {
event.preventDefault();
this.setState({showEdit: true});
},
cancelEdit(event) {
event.preventDefault();
this.setState({showEdit: false});
},
editCallback() {
this.setState({showEdit: false});
},
renderComment() {
const htmlBody = {__html: this.props.comment.htmlBody};
return (
<div dangerouslySetInnerHTML={htmlBody}></div>
)
},
renderReply() {
({CommentNew} = Telescope.components);
return (
<div className="comment-reply">
<CommentNew comment={this.props.comment} submitCallback={this.replyCallback} type="reply" />
<a href="#" onClick={this.cancelReply}>Cancel</a>
</div>
)
},
renderEdit() {
({CommentEdit} = Telescope.components);
return (
<CommentEdit comment={this.props.comment} submitCallback={this.editCallback}/>
)
},
renderActions() {
return (
<ul>
<li><a href="#" onClick={this.showReply}>Reply</a></li>
{Users.can.edit(this.props.currentUser, this.props.comment) ? <li><a href="#" onClick={this.showEdit}>Edit</a></li> : ""}
</ul>
)
},
render() {
return (
<div className="comment">
{this.state.showEdit ? this.renderEdit() : this.renderComment()}
{this.renderActions()}
{this.state.showReply ? this.renderReply() : ""}
</div>
)
}
});
module.exports = CommentItem;