Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe65842

Browse files
committed
Do not refetch the entire feed when a comment is deleted
1 parent 7365def commit fe65842

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/components/goals/UpdateComment.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Avatar, Button, Menu } from '@/ui'
1+
import { Avatar, Menu } from '@/ui'
22
import React, { useRef, useState } from 'react'
33
import { Markdown, A, LikeModal, useLikes, EditComment } from '@/components'
44
import { DateTime } from 'luxon'
5-
import { UpdateCommentType } from 'src/pages'
5+
import { HomePageFeedUpdateType, UpdateCommentType } from 'src/pages'
66
import { useSession } from 'next-auth/client'
77
import classNames from 'classnames'
88
import {
@@ -72,7 +72,21 @@ export default function UpdateComment({
7272
id: toastId.current,
7373
icon: <Trash className="text-danger-400" />,
7474
})
75-
queryClient.refetchQueries('/api/fauna/all-updates')
75+
if (queryClient.getQueryState('/api/fauna/all-updates')) {
76+
queryClient.setQueryData<{ updates: HomePageFeedUpdateType[] }>(
77+
'/api/fauna/all-updates',
78+
(oldData) => ({
79+
updates: oldData.updates.map((_update) => {
80+
if (_update.id === comment.updateId) {
81+
_update.comments.data = _update.comments.data.filter(
82+
(_comment) => _comment.id !== comment.id
83+
)
84+
}
85+
return _update
86+
}),
87+
})
88+
)
89+
}
7690
},
7791
onError: () => {
7892
toast.error('Something went wrong!!!', {

0 commit comments

Comments
 (0)