2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-03-17 17:48:25 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-07 15:03:00 +09:00
|
|
|
import moment from 'moment';
|
2016-06-10 10:25:38 +09:00
|
|
|
import { intlShape, FormattedMessage, FormattedRelative } from 'react-intl';
|
2016-06-23 15:00:58 +09:00
|
|
|
import Users from 'meteor/nova:users';
|
2016-10-31 17:13:14 +01:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2016-11-07 23:46:12 +09:00
|
|
|
import NovaForm from "meteor/nova:forms";
|
2016-02-18 16:26:52 +09:00
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
class CommentsItem extends Component{
|
2016-02-18 21:39:33 +09:00
|
|
|
|
2016-03-17 17:48:25 +09:00
|
|
|
constructor() {
|
|
|
|
super();
|
2016-11-13 14:12:15 +01:00
|
|
|
['showReply', 'replyCancelCallback', 'replySuccessCallback', 'showEdit', 'editCancelCallback', 'editSuccessCallback', 'removeSuccessCallback'].forEach(methodName => {this[methodName] = this[methodName].bind(this)});
|
2016-03-17 17:48:25 +09:00
|
|
|
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
|
|
|
|
2016-04-04 09:31:48 +09:00
|
|
|
replyCancelCallback(event) {
|
2016-02-18 16:26:52 +09:00
|
|
|
event.preventDefault();
|
|
|
|
this.setState({showReply: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 16:26:52 +09:00
|
|
|
|
2016-04-04 09:31:48 +09:00
|
|
|
replySuccessCallback() {
|
2016-02-18 21:39:33 +09:00
|
|
|
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
|
|
|
|
2016-04-04 09:31:48 +09:00
|
|
|
editCancelCallback(event) {
|
2016-02-18 21:39:33 +09:00
|
|
|
event.preventDefault();
|
|
|
|
this.setState({showEdit: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
2016-11-08 14:56:48 +09:00
|
|
|
editSuccessCallback() {
|
2016-11-08 18:50:50 +01:00
|
|
|
this.setState({showEdit: false});
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 21:39:33 +09:00
|
|
|
|
2016-11-13 14:12:15 +01:00
|
|
|
removeSuccessCallback({documentId}) {
|
|
|
|
const deleteDocumentSuccess = this.context.intl.formatMessage({id: 'comments.delete_success'});
|
|
|
|
this.props.flash(deleteDocumentSuccess, "success");
|
|
|
|
this.context.events.track("comment deleted", {_id: documentId});
|
2016-05-06 17:07:40 -04:00
|
|
|
}
|
|
|
|
|
2016-02-18 21:39:33 +09:00
|
|
|
renderComment() {
|
|
|
|
const htmlBody = {__html: this.props.comment.htmlBody};
|
|
|
|
|
|
|
|
return (
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="comments-item-text">
|
2016-03-25 12:17:29 +09:00
|
|
|
<div dangerouslySetInnerHTML={htmlBody}></div>
|
2016-06-09 17:42:20 +09:00
|
|
|
{!this.props.comment.isDeleted ? <a className="comments-item-reply-link" onClick={this.showReply}><Telescope.components.Icon name="reply"/> <FormattedMessage id="comments.reply"/></a> : null}
|
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
|
|
|
|
|
|
|
return (
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="comments-item-reply">
|
2016-11-07 23:46:12 +09:00
|
|
|
<Telescope.components.CommentsNewForm
|
2016-04-04 09:31:48 +09:00
|
|
|
postId={this.props.comment.postId}
|
|
|
|
parentComment={this.props.comment}
|
|
|
|
successCallback={this.replySuccessCallback}
|
2016-11-13 14:12:15 +01:00
|
|
|
cancelCallback={this.replyCancelCallback}
|
2016-11-07 23:46:12 +09:00
|
|
|
type="reply"
|
2016-04-04 09:31:48 +09:00
|
|
|
/>
|
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() {
|
|
|
|
|
|
|
|
return (
|
2016-11-07 23:46:12 +09:00
|
|
|
<Telescope.components.CommentsEditForm
|
|
|
|
comment={this.props.comment}
|
2016-04-04 09:31:48 +09:00
|
|
|
successCallback={this.editSuccessCallback}
|
|
|
|
cancelCallback={this.editCancelCallback}
|
2016-11-13 14:12:15 +01:00
|
|
|
removeSuccessCallback={this.removeSuccessCallback}
|
2016-04-04 09:31:48 +09:00
|
|
|
/>
|
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
|
|
|
const comment = this.props.comment;
|
|
|
|
|
2016-02-18 21:39:33 +09:00
|
|
|
return (
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="comments-item" id={comment._id}>
|
|
|
|
<div className="comments-item-body">
|
|
|
|
<div className="comments-item-meta">
|
2016-05-22 16:42:24 +09:00
|
|
|
<Telescope.components.UsersAvatar size="small" user={comment.user}/>
|
|
|
|
<Telescope.components.UsersName user={comment.user}/>
|
2016-06-10 10:25:38 +09:00
|
|
|
<div className="comments-item-date"><FormattedRelative value={comment.postedAt}/></div>
|
2016-08-06 19:47:04 +02:00
|
|
|
<Telescope.components.CanDo action="comments.edit" document={this.props.comment}>
|
|
|
|
<div>
|
|
|
|
<a className="comment-edit" onClick={this.showEdit}><FormattedMessage id="comments.edit"/></a>
|
|
|
|
</div>
|
|
|
|
</Telescope.components.CanDo>
|
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
|
|
|
}
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
CommentsItem.propTypes = {
|
2016-03-17 17:48:25 +09:00
|
|
|
comment: React.PropTypes.object.isRequired, // the current comment
|
2016-10-14 08:47:18 +02:00
|
|
|
};
|
2016-02-16 16:12:13 +09:00
|
|
|
|
2016-06-09 17:42:20 +09:00
|
|
|
CommentsItem.contextTypes = {
|
2016-08-06 19:47:04 +02:00
|
|
|
currentUser: React.PropTypes.object,
|
2016-06-14 17:03:35 +09:00
|
|
|
events: React.PropTypes.object,
|
2016-06-09 17:42:20 +09:00
|
|
|
intl: intlShape
|
2016-10-14 08:47:18 +02:00
|
|
|
};
|
2016-06-09 17:42:20 +09:00
|
|
|
|
2016-10-31 17:13:14 +01:00
|
|
|
const mapStateToProps = state => ({ messages: state.messages, });
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
|
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(CommentsItem);
|