Unverified Commit b5a68924 authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub

Merge pull request #5651 from paulkaplan/update-reply-count-for-new-replies

Update the reply_count when you leave a reply
parents e331c20d 614cfdc4
...@@ -70,7 +70,17 @@ module.exports.commentsReducer = (state, action) => { ...@@ -70,7 +70,17 @@ module.exports.commentsReducer = (state, action) => {
return Object.assign({}, state, { return Object.assign({}, state, {
replies: Object.assign({}, state.replies, { replies: Object.assign({}, state.replies, {
// Replies to comments go at the end of the thread // Replies to comments go at the end of the thread
[action.topLevelCommentId]: state.replies[action.topLevelCommentId].concat(action.comment) [action.topLevelCommentId]:
(state.replies[action.topLevelCommentId] || [])
.concat(action.comment)
}),
comments: state.comments.map(comment => {
if (comment.id === action.topLevelCommentId) {
return Object.assign({}, comment, {
reply_count: comment.reply_count + 1
});
}
return comment;
}) })
}); });
} }
......
...@@ -43,9 +43,9 @@ tap.test('setComments', t => { ...@@ -43,9 +43,9 @@ tap.test('setComments', t => {
const commentState = { const commentState = {
comments: [ comments: [
{id: 'id1', visibility: 'visible'}, {id: 'id1', visibility: 'visible', reply_count: 2},
{id: 'id2', visibility: 'visible'}, {id: 'id2', visibility: 'visible', reply_count: 0},
{id: 'id3', visibility: 'visible'} {id: 'id3', visibility: 'visible', reply_count: 0}
], ],
replies: { replies: {
id1: [ id1: [
...@@ -108,6 +108,12 @@ tap.test('addNewComment, reply comment', t => { ...@@ -108,6 +108,12 @@ tap.test('addNewComment, reply comment', t => {
state = reducer(commentState, Comments.addNewComment({id: 'new comment'}, 'id1')); state = reducer(commentState, Comments.addNewComment({id: 'new comment'}, 'id1'));
// Adds replies to the end of the replies list // Adds replies to the end of the replies list
t.equal(state.replies.id1[2].id, 'new comment'); t.equal(state.replies.id1[2].id, 'new comment');
t.equal(state.comments[0].reply_count, 3);
// Also check a top-level comment that doesn't have replies yet
state = reducer(commentState, Comments.addNewComment({id: 'new comment2'}, 'id2'));
t.equal(state.replies.id2[0].id, 'new comment2');
t.equal(state.comments[1].reply_count, 1);
t.end(); t.end();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment