Skip to content

Commit

Permalink
fix: comment transition
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed May 4, 2024
1 parent 38655f2 commit a2bf130
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
14 changes: 5 additions & 9 deletions src/components/modules/comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,11 @@ export const Comment: Component<{
: true
}
transition={softSpringPreset}
animate={
comment['new']
? {
opacity: 1,
y: 0,
scale: 1,
}
: void 0
}
animate={{
opacity: 1,
y: 0,
scale: 1,
}}
data-comment-id={cid}
data-parent-id={parentId}
className={clsx('relative my-2', className)}
Expand Down
28 changes: 13 additions & 15 deletions src/socket/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,22 @@ export const eventHandler = (
id: string
}

const queryData = queryClient.getQueryData<
InfiniteData<PaginateResult<CommentModel>>
>(buildCommentsQueryKey(payload.ref))

if (!queryData) return
for (const page of queryData.pages) {
if (page.data.some((comment) => comment.id === payload.id)) {
return
setTimeout(() => {
const queryData = queryClient.getQueryData<
InfiniteData<PaginateResult<CommentModel>>
>(buildCommentsQueryKey(payload.ref))

if (!queryData) return
for (const page of queryData.pages) {
if (page.data.some((comment) => comment.id === payload.id)) {
return
}
}
}

requestAnimationFrame(() => {
requestAnimationFrame(() => {
queryClient.invalidateQueries({
queryKey: buildCommentsQueryKey(payload.ref),
})
queryClient.invalidateQueries({
queryKey: buildCommentsQueryKey(payload.ref),
})
})
}, 1000)

break
}
Expand Down

0 comments on commit a2bf130

Please sign in to comment.