2016-03-17 17:48:25 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-02-18 17:53:04 +09:00
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
class CommentsNode extends Component {
|
2016-02-18 17:53:04 +09:00
|
|
|
|
|
|
|
renderComment(comment) {
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
({CommentsItem} = Telescope.components);
|
2016-02-18 17:53:04 +09:00
|
|
|
|
|
|
|
return (
|
2016-04-14 10:12:35 +09:00
|
|
|
<CommentsItem comment={comment} key={comment._id} currentUser={this.props.currentUser}/>
|
2016-02-18 17:53:04 +09:00
|
|
|
)
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 17:53:04 +09:00
|
|
|
|
|
|
|
renderChildren(children) {
|
|
|
|
return (
|
|
|
|
<div className="comment-children">
|
2016-04-14 10:12:35 +09:00
|
|
|
{children.map(comment => <CommentsNode comment={comment} key={comment._id} currentUser={this.props.currentUser}/>)}
|
2016-02-18 17:53:04 +09:00
|
|
|
</div>
|
|
|
|
)
|
2016-03-17 17:48:25 +09:00
|
|
|
}
|
2016-02-18 17:53:04 +09:00
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
const comment = this.props.comment;
|
|
|
|
const children = this.props.comment.childrenResults;
|
|
|
|
|
|
|
|
return (
|
2016-02-19 09:54:13 +09:00
|
|
|
<div className="comment-node">
|
2016-02-18 17:53:04 +09:00
|
|
|
{this.renderComment(comment)}
|
|
|
|
{children ? this.renderChildren(children) : ""}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-03-17 17:48:25 +09:00
|
|
|
};
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
CommentsNode.propTypes = {
|
2016-03-17 17:48:25 +09:00
|
|
|
comment: React.PropTypes.object.isRequired, // the current comment
|
|
|
|
currentUser: React.PropTypes.object, // the current user
|
|
|
|
}
|
2016-02-18 17:53:04 +09:00
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
module.exports = CommentsNode;
|