diff --git a/src/state/queries/messages/leave-conversation.ts b/src/state/queries/messages/leave-conversation.ts index d7d47b2741..9f45de5445 100644 --- a/src/state/queries/messages/leave-conversation.ts +++ b/src/state/queries/messages/leave-conversation.ts @@ -31,6 +31,7 @@ export function useLeaveConvo( return data }, onMutate: () => { + let prevPages: ChatBskyConvoListConvos.OutputSchema[] = [] queryClient.setQueryData( CONVO_LIST_KEY, (old?: { @@ -38,6 +39,7 @@ export function useLeaveConvo( pages: Array }) => { if (!old) return old + prevPages = old.pages return { ...old, pages: old.pages.map(page => { @@ -49,13 +51,27 @@ export function useLeaveConvo( } }, ) + return {prevPages} }, onSuccess: data => { queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY}) onSuccess?.(data) }, - onError: error => { + onError: (error, _, context) => { logger.error(error) + queryClient.setQueryData( + CONVO_LIST_KEY, + (old?: { + pageParams: Array + pages: Array + }) => { + if (!old) return old + return { + ...old, + pages: context?.prevPages || old.pages, + } + }, + ) queryClient.invalidateQueries({queryKey: CONVO_LIST_KEY}) onError?.(error) },