diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-01-22 21:03:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-22 21:03:31 +0000 |
commit | 74bb65714b7c7b128ddb27438773b149bbe5ec6c (patch) | |
tree | 83f3348e762938185977b74e51a10f96d4229bc3 /src/state/queries/messages | |
parent | 638008c781d4ccb038de57344e18a5237a0f371d (diff) | |
download | voidsky-74bb65714b7c7b128ddb27438773b149bbe5ec6c.tar.zst |
Post-report menu (#7446)
* post-report block/delete dialog * fix * default checked * web styles * add icon to send button * wire everything up * optimisically leave convo * hide pending-leave convos * Capitalize action labels * Code style --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/state/queries/messages')
-rw-r--r-- | src/state/queries/messages/leave-conversation.ts | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/state/queries/messages/leave-conversation.ts b/src/state/queries/messages/leave-conversation.ts index faeb92696..21cd1f18c 100644 --- a/src/state/queries/messages/leave-conversation.ts +++ b/src/state/queries/messages/leave-conversation.ts @@ -1,17 +1,28 @@ import {ChatBskyConvoLeaveConvo, ChatBskyConvoListConvos} from '@atproto/api' -import {useMutation, useQueryClient} from '@tanstack/react-query' +import { + useMutation, + useMutationState, + useQueryClient, +} from '@tanstack/react-query' import {logger} from '#/logger' import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' import {useAgent} from '#/state/session' import {RQKEY as CONVO_LIST_KEY} from './list-conversations' +const RQKEY_ROOT = 'leave-convo' +export function RQKEY(convoId: string | undefined) { + return [RQKEY_ROOT, convoId] +} + export function useLeaveConvo( convoId: string | undefined, { onSuccess, + onMutate, onError, }: { + onMutate?: () => void onSuccess?: (data: ChatBskyConvoLeaveConvo.OutputSchema) => void onError?: (error: Error) => void }, @@ -20,6 +31,7 @@ export function useLeaveConvo( const agent = useAgent() return useMutation({ + mutationKey: RQKEY(convoId), mutationFn: async () => { if (!convoId) throw new Error('No convoId provided') @@ -51,6 +63,7 @@ export function useLeaveConvo( } }, ) + onMutate?.() return {prevPages} }, onSuccess: data => { @@ -77,3 +90,20 @@ export function useLeaveConvo( }, }) } + +/** + * Gets currently pending and successful leave convo mutations + * + * @returns Array of `convoId` + */ +export function useLeftConvos() { + const pending = useMutationState({ + filters: {mutationKey: [RQKEY_ROOT], status: 'pending'}, + select: mutation => mutation.options.mutationKey?.[1] as string | undefined, + }) + const success = useMutationState({ + filters: {mutationKey: [RQKEY_ROOT], status: 'success'}, + select: mutation => mutation.options.mutationKey?.[1] as string | undefined, + }) + return [...pending, ...success].filter(id => id !== undefined) +} |