actually optimistic mark as read (#3917)
parent
7d06fb9432
commit
750a5c899b
|
@ -1,8 +1,9 @@
|
||||||
import {BskyAgent} from '@atproto-labs/api'
|
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 {useOnMarkAsRead} from '#/state/queries/messages/list-converations'
|
||||||
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
|
import {useDmServiceUrlStorage} from '#/screens/Messages/Temp/useDmServiceUrlStorage'
|
||||||
|
import {RQKEY as LIST_CONVOS_KEY} from './list-converations'
|
||||||
import {useHeaders} from './temp-headers'
|
import {useHeaders} from './temp-headers'
|
||||||
|
|
||||||
const RQKEY_ROOT = 'convo'
|
const RQKEY_ROOT = 'convo'
|
||||||
|
@ -28,7 +29,8 @@ export function useConvoQuery(convoId: string) {
|
||||||
export function useMarkAsReadMutation() {
|
export function useMarkAsReadMutation() {
|
||||||
const headers = useHeaders()
|
const headers = useHeaders()
|
||||||
const {serviceUrl} = useDmServiceUrlStorage()
|
const {serviceUrl} = useDmServiceUrlStorage()
|
||||||
const onMarkAsRead = useOnMarkAsRead()
|
const optimisticUpdate = useOnMarkAsRead()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
|
@ -50,8 +52,11 @@ export function useMarkAsReadMutation() {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onSuccess(_, {convoId}) {
|
onMutate({convoId}) {
|
||||||
onMarkAsRead(convoId)
|
optimisticUpdate(convoId)
|
||||||
|
},
|
||||||
|
onSettled() {
|
||||||
|
queryClient.invalidateQueries({queryKey: LIST_CONVOS_KEY})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,6 @@ export function useOnMarkAsRead() {
|
||||||
unreadCount: 0,
|
unreadCount: 0,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
queryClient.invalidateQueries({queryKey: RQKEY})
|
|
||||||
},
|
},
|
||||||
[queryClient],
|
[queryClient],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue