Reset leave chat optimistic update if fails (#4058)
parent
5e5716c0a8
commit
449f16b7c5
|
@ -31,6 +31,7 @@ export function useLeaveConvo(
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
onMutate: () => {
|
onMutate: () => {
|
||||||
|
let prevPages: ChatBskyConvoListConvos.OutputSchema[] = []
|
||||||
queryClient.setQueryData(
|
queryClient.setQueryData(
|
||||||
CONVO_LIST_KEY,
|
CONVO_LIST_KEY,
|
||||||
(old?: {
|
(old?: {
|
||||||
|
@ -38,6 +39,7 @@ export function useLeaveConvo(
|
||||||
pages: Array<ChatBskyConvoListConvos.OutputSchema>
|
pages: Array<ChatBskyConvoListConvos.OutputSchema>
|
||||||
}) => {
|
}) => {
|
||||||
if (!old) return old
|
if (!old) return old
|
||||||
|
prevPages = old.pages
|
||||||
return {
|
return {
|
||||||
...old,
|
...old,
|
||||||
pages: old.pages.map(page => {
|
pages: old.pages.map(page => {
|
||||||
|
@ -49,13 +51,27 @@ export function useLeaveConvo(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
return {prevPages}
|
||||||
},
|
},
|
||||||
onSuccess: data => {
|
onSuccess: data => {
|
||||||
queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY})
|
queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY})
|
||||||
onSuccess?.(data)
|
onSuccess?.(data)
|
||||||
},
|
},
|
||||||
onError: error => {
|
onError: (error, _, context) => {
|
||||||
logger.error(error)
|
logger.error(error)
|
||||||
|
queryClient.setQueryData(
|
||||||
|
CONVO_LIST_KEY,
|
||||||
|
(old?: {
|
||||||
|
pageParams: Array<string | undefined>
|
||||||
|
pages: Array<ChatBskyConvoListConvos.OutputSchema>
|
||||||
|
}) => {
|
||||||
|
if (!old) return old
|
||||||
|
return {
|
||||||
|
...old,
|
||||||
|
pages: context?.prevPages || old.pages,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY})
|
queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY})
|
||||||
onError?.(error)
|
onError?.(error)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue