Skip to content

Commit

Permalink
Prevent edit timer jump
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed May 8, 2024
1 parent 0778b25 commit f0dacf7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions components/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const cacheUpdateAncestors = (cache, ancestors) => {

const cacheRemovePendingComment = (cache, parentId) => {
const id = PENDING_COMMENT_ID
const pendingComment = cache.readFragment({
id: `Item:${id}`,
fragment: COMMENTS,
fragmentName: 'CommentsRecursive'
})
cache.modify({
id: `Item:${parentId}`,
fields: {
Expand All @@ -57,6 +62,7 @@ const cacheRemovePendingComment = (cache, parentId) => {
}
}
})
return pendingComment
}

const cacheRevertAncestorUpdate = (cache, ancestors) => {
Expand Down Expand Up @@ -167,8 +173,10 @@ export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children
}
}`, {
update (cache, { data: { upsertComment } }) {
cacheRemovePendingComment(cache, parentId)
cacheAddComment(cache, parentId, upsertComment)
// prevent edit timer jump
const pendingComment = cacheRemovePendingComment(cache, parentId)
const comment = { ...upsertComment, createdAt: pendingComment.createdAt }
cacheAddComment(cache, parentId, comment)

const ancestors = item.path.split('.')
// XXX cache update already applied
Expand Down

0 comments on commit f0dacf7

Please sign in to comment.