From ced67876cc9acbff3746151db3aa06dbf8ab7786 Mon Sep 17 00:00:00 2001 From: rshigg <90143161+rshigg@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:06:00 -0330 Subject: [PATCH] Add ability to block account from post dropdown menu (#6091) Co-authored-by: Hailey Co-authored-by: Hailey --- src/state/queries/profile.ts | 2 +- .../util/forms/PostDropdownBtnMenuItems.tsx | 56 ++++++++++++++++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 84f209d95d..63c405788d 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -409,7 +409,7 @@ function useProfileUnmuteMutation() { } export function useProfileBlockMutationQueue( - profile: Shadow, + profile: Shadow, ) { const queryClient = useQueryClient() const did = profile.did diff --git a/src/view/com/util/forms/PostDropdownBtnMenuItems.tsx b/src/view/com/util/forms/PostDropdownBtnMenuItems.tsx index 05d8efdbc0..149bb9ad2f 100644 --- a/src/view/com/util/forms/PostDropdownBtnMenuItems.tsx +++ b/src/view/com/util/forms/PostDropdownBtnMenuItems.tsx @@ -29,6 +29,7 @@ import {getTranslatorLink} from '#/locale/helpers' import {logger} from '#/logger' import {isWeb} from '#/platform/detection' import {Shadow} from '#/state/cache/post-shadow' +import {useProfileShadow} from '#/state/cache/profile-shadow' import {useFeedFeedbackContext} from '#/state/feed-feedback' import {useLanguagePrefs} from '#/state/preferences' import {useHiddenPosts, useHiddenPostsApi} from '#/state/preferences' @@ -39,6 +40,7 @@ import { } from '#/state/queries/post' import {useToggleQuoteDetachmentMutation} from '#/state/queries/postgate' import {getMaybeDetachedQuoteEmbed} from '#/state/queries/postgate/util' +import {useProfileBlockMutationQueue} from '#/state/queries/profile' import {useToggleReplyVisibilityMutation} from '#/state/queries/threadgate' import {useSession} from '#/state/session' import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies' @@ -64,6 +66,7 @@ import {EyeSlash_Stroke2_Corner0_Rounded as EyeSlash} from '#/components/icons/E import {Filter_Stroke2_Corner0_Rounded as Filter} from '#/components/icons/Filter' import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute' import {PaperPlane_Stroke2_Corner0_Rounded as Send} from '#/components/icons/PaperPlane' +import {PersonX_Stroke2_Corner0_Rounded as PersonX} from '#/components/icons/Person' import {Pin_Stroke2_Corner0_Rounded as PinIcon} from '#/components/icons/Pin' import {SettingsGear2_Stroke2_Corner0_Rounded as Gear} from '#/components/icons/SettingsGear2' import {SpeakerVolumeFull_Stroke2_Corner0_Rounded as Unmute} from '#/components/icons/Speaker' @@ -107,6 +110,7 @@ let PostDropdownMenuItems = ({ const openLink = useOpenLink() const navigation = useNavigation() const {mutedWordsDialogControl} = useGlobalDialogsControlContext() + const blockPromptControl = useDialogControl() const reportDialogControl = useReportDialogControl() const deletePromptControl = useDialogControl() const hidePromptControl = useDialogControl() @@ -121,7 +125,7 @@ let PostDropdownMenuItems = ({ const postUri = post.uri const postCid = post.cid - const postAuthor = post.author + const postAuthor = useProfileShadow(post.author) const quoteEmbed = React.useMemo(() => { if (!currentAccount || !post.embed) return return getMaybeDetachedQuoteEmbed({ @@ -148,6 +152,8 @@ let PostDropdownMenuItems = ({ const {mutateAsync: toggleQuoteDetachment, isPending: isDetachPending} = useToggleQuoteDetachmentMutation() + const [queueBlock] = useProfileBlockMutationQueue(postAuthor) + const prefetchPostInteractionSettings = usePrefetchPostInteractionSettings({ postUri: post.uri, rootPostUri: rootUri, @@ -348,6 +354,18 @@ let PostDropdownMenuItems = ({ }) }, [isPinned, pinPostMutate, postCid, postUri]) + const onBlockAuthor = useCallback(async () => { + try { + await queueBlock() + Toast.show(_(msg`Account blocked`)) + } catch (e: any) { + if (e?.name !== 'AbortError') { + logger.error('Failed to block account', {message: e}) + Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark') + } + } + }, [_, queueBlock]) + return ( <> @@ -578,13 +596,24 @@ let PostDropdownMenuItems = ({ {!isAuthor && ( - reportDialogControl.open()}> - {_(msg`Report post`)} - - + <> + {!postAuthor.viewer?.blocking && ( + blockPromptControl.open()}> + {_(msg`Block account`)} + + + )} + reportDialogControl.open()}> + {_(msg`Report post`)} + + + )} {isAuthor && ( @@ -704,6 +733,17 @@ let PostDropdownMenuItems = ({ onConfirm={onToggleReplyVisibility} confirmButtonCta={_(msg`Yes, hide`)} /> + + ) }