actually optimistic mark as read (#3917)

zio/stable
Samuel Newman 2024-05-08 21:19:45 +01:00 committed by GitHub
parent 7d06fb9432
commit 750a5c899b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -1,8 +1,9 @@
import {BskyAgent} from '@atproto-labs/api'
import {useMutation, useQuery} from '@tanstack/react-query'
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {useOnMarkAsRead} from '#/state/queries/messages/list-converations'
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
import {RQKEY as LIST_CONVOS_KEY} from './list-converations'
import {useHeaders} from './temp-headers'
const RQKEY_ROOT = 'convo'
@ -28,7 +29,8 @@ export function useConvoQuery(convoId: string) {
export function useMarkAsReadMutation() {
const headers = useHeaders()
const {serviceUrl} = useDmServiceUrlStorage()
const onMarkAsRead = useOnMarkAsRead()
const optimisticUpdate = useOnMarkAsRead()
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({
@ -50,8 +52,11 @@ export function useMarkAsReadMutation() {
},
)
},
onSuccess(_, {convoId}) {
onMarkAsRead(convoId)
onMutate({convoId}) {
optimisticUpdate(convoId)
},
onSettled() {
queryClient.invalidateQueries({queryKey: LIST_CONVOS_KEY})
},
})
}

View File

@ -122,7 +122,6 @@ export function useOnMarkAsRead() {
unreadCount: 0,
}))
})
queryClient.invalidateQueries({queryKey: RQKEY})
},
[queryClient],
)