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 { this.setState({body: e.target.value})} diff --git a/client/coral-plugin-replies/ReplyBox.js b/client/coral-plugin-replies/ReplyBox.js index d496a63f7..6ecd9eef3 100644 --- a/client/coral-plugin-replies/ReplyBox.js +++ b/client/coral-plugin-replies/ReplyBox.js @@ -8,7 +8,8 @@ const ReplyBox = (props) => { props.showReply && props.updateItem(props.item_id || props.parent_id, 'showReply', true)}> + onClick={(e) => props.updateItem(props.id || props.parent_id, 'showReply', true)}> reply {lang.t('reply')} diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 428369ae1..57c434a6f 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -46,6 +46,7 @@ router.post('/:comment_id', (req, res, next) => { comment.asset_id = req.body.asset_id; comment.parent_id = req.body.parent_id; comment.status = req.body.status; + comment.username = req.body.username; comment.save().then((comment) => { res.status(200).send(comment); diff --git a/routes/api/stream/index.js b/routes/api/stream/index.js index c63bf871d..5c3333ac8 100644 --- a/routes/api/stream/index.js +++ b/routes/api/stream/index.js @@ -17,6 +17,7 @@ router.get('/', (req, res, next) => { Action.findByItemIdArray(comments.map((comment) => comment.id)) ]); }).then(([comments, users, actions]) => { + console.log(comments.length); res.json([...comments,...users,...actions]); }).catch(error => { next(error);