Fix paginated comments button not showing on comment injection/creation (#2426)
* fix: also tick nDirectComments to respect pagination logic * update nDirectComments only for the provided parentId * explicit type conversion
This commit is contained in:
parent
baa92c0ddc
commit
a3c5a33bc4
@ -83,7 +83,7 @@ export default forwardRef(function Reply ({
|
|||||||
const ancestors = item.path.split('.')
|
const ancestors = item.path.split('.')
|
||||||
|
|
||||||
// update all ancestors
|
// update all ancestors
|
||||||
updateAncestorsCommentCount(cache, ancestors, 1)
|
updateAncestorsCommentCount(cache, ancestors, 1, parentId)
|
||||||
|
|
||||||
// so that we don't see indicator for our own comments, we record this comments as the latest time
|
// so that we don't see indicator for our own comments, we record this comments as the latest time
|
||||||
// but we also have record num comments, in case someone else commented when we did
|
// but we also have record num comments, in case someone else commented when we did
|
||||||
|
|||||||
@ -42,6 +42,7 @@ function prepareComments (item, cache, newComment) {
|
|||||||
? {
|
? {
|
||||||
...item,
|
...item,
|
||||||
ncomments: item.ncomments + totalNComments,
|
ncomments: item.ncomments + totalNComments,
|
||||||
|
nDirectComments: item.nDirectComments + 1,
|
||||||
comments: {
|
comments: {
|
||||||
...item.comments,
|
...item.comments,
|
||||||
comments: [injectedComment, ...item.comments.comments]
|
comments: [injectedComment, ...item.comments.comments]
|
||||||
@ -50,7 +51,8 @@ function prepareComments (item, cache, newComment) {
|
|||||||
// when the fragment doesn't have a comments field, we just update stats fields
|
// when the fragment doesn't have a comments field, we just update stats fields
|
||||||
: {
|
: {
|
||||||
...item,
|
...item,
|
||||||
ncomments: item.ncomments + totalNComments
|
ncomments: item.ncomments + totalNComments,
|
||||||
|
nDirectComments: item.nDirectComments + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { COMMENT_WITH_NEW_RECURSIVE, COMMENT_WITH_NEW_LIMITED, COMMENT_WITH_NEW_
|
|||||||
import { ITEM_FULL } from '../fragments/items'
|
import { ITEM_FULL } from '../fragments/items'
|
||||||
|
|
||||||
// updates the ncomments field of all ancestors of an item/comment in the cache
|
// updates the ncomments field of all ancestors of an item/comment in the cache
|
||||||
export function updateAncestorsCommentCount (cache, ancestors, increment) {
|
export function updateAncestorsCommentCount (cache, ancestors, increment, parentId) {
|
||||||
// update all ancestors
|
// update all ancestors
|
||||||
ancestors.forEach(id => {
|
ancestors.forEach(id => {
|
||||||
cache.modify({
|
cache.modify({
|
||||||
@ -10,6 +10,13 @@ export function updateAncestorsCommentCount (cache, ancestors, increment) {
|
|||||||
fields: {
|
fields: {
|
||||||
ncomments (existingNComments = 0) {
|
ncomments (existingNComments = 0) {
|
||||||
return existingNComments + increment
|
return existingNComments + increment
|
||||||
|
},
|
||||||
|
nDirectComments (existingNDirectComments = 0) {
|
||||||
|
// only increment nDirectComments for the immediate parent
|
||||||
|
if (parentId && Number(id) === Number(parentId)) {
|
||||||
|
return existingNDirectComments + 1
|
||||||
|
}
|
||||||
|
return existingNDirectComments
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
optimistic: true
|
optimistic: true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user