2016-03-17 17:48:25 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-02-18 16:26:52 +09:00
|
|
|
|
2016-03-17 17:48:25 +09:00
|
|
|
class CommentItem extends Component{
|
2016-02-18 21:39:33 +09:00
|
|
|
|
2016-03-17 17:48:25 +09:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
['showReply', 'cancelReply', 'replyCallback', 'showEdit', 'cancelEdit', 'editCallback'].forEach(methodName => {this[methodName] = this[methodName].bind(this)});
|
|
|
|
this.state = {
|
2016-02-18 21:39:33 +09:00
|
|
|
showReply: false,
|
|
|
|
showEdit: false
|
|
|
|
};
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 16:26:52 +09:00
|
|
|
|
|
|
|
showReply(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({showReply: true});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 16:26:52 +09:00
|
|
|
|
|
|
|
cancelReply(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({showReply: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 16:26:52 +09:00
|
|
|
|
2016-02-18 21:39:33 +09:00
|
|
|
replyCallback() {
|
|
|
|
this.setState({showReply: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
|
|
|
showEdit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({showEdit: true});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
|
|
|
cancelEdit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({showEdit: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
|
|
|
editCallback() {
|
|
|
|
this.setState({showEdit: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
|
|
|
renderComment() {
|
|
|
|
const htmlBody = {__html: this.props.comment.htmlBody};
|
|
|
|
|
|
|
|
return (
|
2016-03-25 12:17:29 +09:00
|
|
|
<div className="comment-text">
|
|
|
|
<div dangerouslySetInnerHTML={htmlBody}></div>
|
2016-03-28 11:41:22 +09:00
|
|
|
<a className="comment-reply-link" onClick={this.showReply}><Icon name="reply"/> Reply</a>
|
2016-03-25 12:17:29 +09:00
|
|
|
</div>
|
2016-02-18 21:39:33 +09:00
|
|
|
)
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
2016-02-18 17:53:04 +09:00
|
|
|
renderReply() {
|
2016-02-18 16:26:52 +09:00
|
|
|
|
2016-02-18 17:53:04 +09:00
|
|
|
({CommentNew} = Telescope.components);
|
2016-02-18 16:26:52 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="comment-reply">
|
2016-02-23 16:49:56 +09:00
|
|
|
<CommentNew postId={this.props.comment.postId} parentComment={this.props.comment} submitCallback={this.replyCallback} cancelCallback={this.cancelReply} type="reply" />
|
2016-02-18 16:26:52 +09:00
|
|
|
</div>
|
|
|
|
)
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 16:26:52 +09:00
|
|
|
|
2016-02-18 21:39:33 +09:00
|
|
|
renderEdit() {
|
|
|
|
|
|
|
|
({CommentEdit} = Telescope.components);
|
|
|
|
|
|
|
|
return (
|
2016-02-19 10:12:08 +09:00
|
|
|
<CommentEdit comment={this.props.comment} submitCallback={this.editCallback} cancelCallback={this.cancelEdit}/>
|
2016-02-18 21:39:33 +09:00
|
|
|
)
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 17:53:04 +09:00
|
|
|
|
2016-02-18 21:39:33 +09:00
|
|
|
render() {
|
2016-03-19 18:19:28 +09:00
|
|
|
|
|
|
|
({UserAvatar} = Telescope.components);
|
|
|
|
|
|
|
|
const comment = this.props.comment;
|
|
|
|
|
2016-02-18 21:39:33 +09:00
|
|
|
return (
|
2016-02-19 10:12:08 +09:00
|
|
|
<div className="comment-item">
|
|
|
|
<div className="comment-body">
|
2016-03-19 18:19:28 +09:00
|
|
|
<div className="comment-meta">
|
2016-03-25 12:17:29 +09:00
|
|
|
<UserAvatar size="small" user={comment.user}/>
|
|
|
|
<UserName user={comment.user}/>
|
|
|
|
<div className="comment-date">{moment(comment.postedAt).fromNow()}</div>
|
2016-03-28 11:41:22 +09:00
|
|
|
{Users.can.edit(this.props.currentUser, this.props.comment) ? <a className="comment-edit" onClick={this.showEdit}>Edit</a> : null}
|
2016-03-19 18:19:28 +09:00
|
|
|
</div>
|
2016-02-19 10:12:08 +09:00
|
|
|
{this.state.showEdit ? this.renderEdit() : this.renderComment()}
|
|
|
|
</div>
|
2016-03-25 12:17:29 +09:00
|
|
|
{this.state.showReply ? this.renderReply() : null}
|
2016-02-18 21:39:33 +09:00
|
|
|
</div>
|
2016-02-18 16:26:52 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
CommentItem.propTypes = {
|
|
|
|
comment: React.PropTypes.object.isRequired, // the current comment
|
|
|
|
currentUser: React.PropTypes.object, // the current user
|
|
|
|
}
|
2016-02-16 16:12:13 +09:00
|
|
|
|
|
|
|
module.exports = CommentItem;
|