Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
b5a68924
Unverified
Commit
b5a68924
authored
Jun 23, 2021
by
Paul Kaplan
Committed by
GitHub
Jun 23, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5651 from paulkaplan/update-reply-count-for-new-replies
Update the reply_count when you leave a reply
parents
e331c20d
614cfdc4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
src/redux/comments.js
src/redux/comments.js
+11
-1
test/unit-legacy/redux/comments-test.js
test/unit-legacy/redux/comments-test.js
+9
-3
No files found.
src/redux/comments.js
View file @
b5a68924
...
@@ -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
;
})
})
});
});
}
}
...
...
test/unit-legacy/redux/comments-test.js
View file @
b5a68924
...
@@ -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
();
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment