From 4737e846812dd30dce2fab935514b42be18d06ab Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 7 Nov 2016 16:11:10 -0500 Subject: [PATCH] Displaying comments and replies appropriately. --- client/coral-embed-stream/src/CommentStream.js | 6 ++++-- client/coral-plugin-commentbox/CommentBox.js | 16 ++++++++-------- client/coral-plugin-replies/ReplyBox.js | 3 ++- client/coral-plugin-replies/ReplyButton.js | 2 +- routes/api/comments/index.js | 1 + routes/api/stream/index.js | 1 + 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index 787cba78a..b8ec5c762 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -111,7 +111,8 @@ class CommentStream extends Component { postItem={this.props.postItem} appendItemArray={this.props.appendItemArray} updateItem={this.props.updateItem} - id={rootItemId}/> + id={rootItemId} + reply={false}/> { rootItem.comments.map((commentId) => { @@ -137,7 +138,8 @@ class CommentStream extends Component { postItem={this.props.postItem} appendItemArray={this.props.appendItemArray} updateItem={this.props.updateItem} - id={commentId} + id={rootItemId} + parent_id={commentId} showReply={comment.showReply}/> { comment.children && diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index 1bd138af9..b7d282f10 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -19,26 +19,26 @@ class CommentBox extends Component { } postComment = () => { - const {postItem, updateItem, id, reply, addNotification, appendItemArray} = this.props + const {postItem, updateItem, id, parent_id, addNotification, appendItemArray} = this.props let comment = { body: this.state.body, asset_id: id, username: this.state.username } let related - if (reply) { - comment.parent_id = id + if (parent_id) { + comment.parent_id = parent_id related = 'children' } else { related = 'comments' } - updateItem(id, 'showReply', false) + updateItem(parent_id, 'showReply', false) postItem(comment, 'comments') .then((comment_id) => { - appendItemArray(id, related, comment_id) + appendItemArray(parent_id || id, related, comment_id) addNotification('success', 'Your comment has been posted.') }).catch((err) => console.error(err)) - this.setState({content: ''}) + this.setState({body: ''}) } render () { @@ -49,7 +49,7 @@ class CommentBox extends Component { this.setState({username: e.target.value})}/> @@ -65,7 +65,7 @@ class CommentBox extends Component {