|
@@ -110,10 +110,10 @@ class PageComments extends React.Component {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // adds replies to specific comment object
|
|
|
|
|
- addRepliesToComments(comment, replies) {
|
|
|
|
|
|
|
+ // get replies to specific comment object
|
|
|
|
|
+ getRepliesFor(comment, allReplies) {
|
|
|
const replyList = [];
|
|
const replyList = [];
|
|
|
- replies.forEach((reply) => {
|
|
|
|
|
|
|
+ allReplies.forEach((reply) => {
|
|
|
if (reply.replyTo === comment._id) {
|
|
if (reply.replyTo === comment._id) {
|
|
|
replyList.push(reply);
|
|
replyList.push(reply);
|
|
|
}
|
|
}
|
|
@@ -122,68 +122,49 @@ class PageComments extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * generate Elements of Comment
|
|
|
|
|
|
|
+ * render Elements of Comment Thread
|
|
|
*
|
|
*
|
|
|
- * @param {any} comments Array of Comment Model Obj
|
|
|
|
|
|
|
+ * @param {any} comment Comment Model Obj
|
|
|
|
|
+ * @param {any} replies List of Reply Comment Model Obj
|
|
|
*
|
|
*
|
|
|
* @memberOf PageComments
|
|
* @memberOf PageComments
|
|
|
*/
|
|
*/
|
|
|
- generateCommentElements(comments, replies) {
|
|
|
|
|
- return comments.map((comment) => {
|
|
|
|
|
|
|
+ renderThread(comment, replies) {
|
|
|
|
|
+ const commentId = comment._id;
|
|
|
|
|
+ const showEditor = this.state.showEditorIds.has(commentId);
|
|
|
|
|
+ const username = this.props.appContainer.me;
|
|
|
|
|
|
|
|
- const commentId = comment._id;
|
|
|
|
|
- const showEditor = this.state.showEditorIds.has(commentId);
|
|
|
|
|
- const username = this.props.appContainer.me;
|
|
|
|
|
-
|
|
|
|
|
- const replyList = this.addRepliesToComments(comment, replies);
|
|
|
|
|
-
|
|
|
|
|
- return (
|
|
|
|
|
- <div key={commentId}>
|
|
|
|
|
- <Comment
|
|
|
|
|
- comment={comment}
|
|
|
|
|
- deleteBtnClicked={this.confirmToDeleteComment}
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div key={commentId} className="mb-5">
|
|
|
|
|
+ <Comment
|
|
|
|
|
+ comment={comment}
|
|
|
|
|
+ deleteBtnClicked={this.confirmToDeleteComment}
|
|
|
|
|
+ growiRenderer={this.growiRenderer}
|
|
|
|
|
+ replyList={replies}
|
|
|
|
|
+ />
|
|
|
|
|
+ { !showEditor && username && (
|
|
|
|
|
+ <Button
|
|
|
|
|
+ bsStyle="default"
|
|
|
|
|
+ className="btn btn-outline btn-default btn-sm"
|
|
|
|
|
+ onClick={() => { return this.replyButtonClickedHandler(commentId) }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <i className="icon-fw icon-action-redo"></i> Reply
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ { showEditor && (
|
|
|
|
|
+ <CommentEditor
|
|
|
growiRenderer={this.growiRenderer}
|
|
growiRenderer={this.growiRenderer}
|
|
|
- replyList={replyList}
|
|
|
|
|
|
|
+ replyTo={commentId}
|
|
|
|
|
+ commentButtonClickedHandler={this.commentButtonClickedHandler}
|
|
|
/>
|
|
/>
|
|
|
- <div className="container-fluid">
|
|
|
|
|
- <div className="row">
|
|
|
|
|
- <div className="col-xs-offset-1 col-xs-11 col-sm-offset-1 col-sm-11 col-md-offset-1 col-md-11 col-lg-offset-1 col-lg-11">
|
|
|
|
|
- { !showEditor && (
|
|
|
|
|
- <div>
|
|
|
|
|
- { username
|
|
|
|
|
- && (
|
|
|
|
|
- <div className="col-xs-offset-6 col-sm-offset-6 col-md-offset-6 col-lg-offset-6">
|
|
|
|
|
- <Button
|
|
|
|
|
- bsStyle="primary"
|
|
|
|
|
- className="fcbtn btn btn-outline btn-rounded btn-xxs"
|
|
|
|
|
- onClick={() => { return this.replyButtonClickedHandler(commentId) }}
|
|
|
|
|
- >
|
|
|
|
|
- Reply <i className="fa fa-mail-reply"></i>
|
|
|
|
|
- </Button>
|
|
|
|
|
- </div>
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- </div>
|
|
|
|
|
- )}
|
|
|
|
|
- { showEditor && (
|
|
|
|
|
- <CommentEditor
|
|
|
|
|
- growiRenderer={this.growiRenderer}
|
|
|
|
|
- replyTo={commentId}
|
|
|
|
|
- commentButtonClickedHandler={this.commentButtonClickedHandler}
|
|
|
|
|
- />
|
|
|
|
|
- )}
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- <br />
|
|
|
|
|
- </div>
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const currentComments = [];
|
|
|
|
|
- const currentReplies = [];
|
|
|
|
|
|
|
+ const topLevelComments = [];
|
|
|
|
|
+ const allReplies = [];
|
|
|
|
|
|
|
|
let comments = this.props.commentContainer.state.comments;
|
|
let comments = this.props.commentContainer.state.comments;
|
|
|
if (this.state.isLayoutTypeGrowi) {
|
|
if (this.state.isLayoutTypeGrowi) {
|
|
@@ -193,31 +174,23 @@ class PageComments extends React.Component {
|
|
|
|
|
|
|
|
comments.forEach((comment) => {
|
|
comments.forEach((comment) => {
|
|
|
if (comment.replyTo === undefined) {
|
|
if (comment.replyTo === undefined) {
|
|
|
- // comment is not a reply
|
|
|
|
|
- currentComments.push(comment);
|
|
|
|
|
|
|
+ // comment is not a reply
|
|
|
|
|
+ topLevelComments.push(comment);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- // comment is a reply
|
|
|
|
|
- currentReplies.push(comment);
|
|
|
|
|
|
|
+ // comment is a reply
|
|
|
|
|
+ allReplies.push(comment);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // generate elements
|
|
|
|
|
- const currentElements = this.generateCommentElements(currentComments, currentReplies);
|
|
|
|
|
-
|
|
|
|
|
- // generate blocks
|
|
|
|
|
- const currentBlock = (
|
|
|
|
|
- <div className="page-comments-list-current" id="page-comments-list-current">
|
|
|
|
|
- {currentElements}
|
|
|
|
|
- </div>
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // layout blocks
|
|
|
|
|
- const commentsElements = (<div>{currentBlock}</div>);
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
- {commentsElements}
|
|
|
|
|
|
|
+ { topLevelComments.map((topLevelComment) => {
|
|
|
|
|
+ // get related replies
|
|
|
|
|
+ const replies = this.getRepliesFor(topLevelComment, allReplies);
|
|
|
|
|
+
|
|
|
|
|
+ return this.renderThread(topLevelComment, replies);
|
|
|
|
|
+ }) }
|
|
|
|
|
|
|
|
<DeleteCommentModal
|
|
<DeleteCommentModal
|
|
|
isShown={this.state.isDeleteConfirmModalShown}
|
|
isShown={this.state.isDeleteConfirmModalShown}
|