Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100/* eslint-disable @typescript-eslint/no-explicit-any */import {memo, type ReactNode} from 'react'import {type Insets} from 'react-native'import {msg} from '@lingui/core/macro'import {useLingui} from '@lingui/react'
import {useCleanError} from '#/lib/hooks/useCleanError'import {type Shadow} from '#/state/cache/post-shadow'import {useFeedFeedbackContext} from '#/state/feed-feedback'import {useHiddenPosts, useHiddenPostsApi} from '#/state/preferences'import {useRequireAuth, useSession} from '#/state/session'import {EyeSlash_Stroke2_Corner0_Rounded as EyeSlash} from '#/components/icons/EyeSlash'import * as Prompt from '#/components/Prompt'import * as toast from '#/components/Toast'import {useAnalytics} from '#/analytics'import {type app} from '#/lexicons'import {PostControlButton, PostControlButtonIcon} from './PostControlButton'
export const HideButton = memo(function HideButton({ post, big, logContext, hitSlop,}: { post: Shadow<app.bsky.feed.defs.PostView> big?: boolean logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' hitSlop?: Insets}): ReactNode { const ax = useAnalytics() const {_} = useLingui() const {currentAccount} = useSession() const hiddenPosts = useHiddenPosts() const {hidePost} = useHiddenPostsApi() const cleanError = useCleanError() const requireAuth = useRequireAuth() const {feedDescriptor} = useFeedFeedbackContext() const hidePromptControl = Prompt.usePromptControl()
const isAuthor = currentAccount?.did === post.author.did const isPostHidden = hiddenPosts?.includes(post.uri)
const onConfirmHide = () => { try { hidePost({uri: post.uri})
ax.metric('thread:click:hideReplyForMe', { uri: post.uri, authorDid: post.author.did, logContext, feedDescriptor, })
toast.show( <toast.Outer> <toast.Icon icon={EyeSlash} /> <toast.Text>{_(msg`Post hidden`)}</toast.Text> </toast.Outer>, ) } catch (e: any) { const {raw, clean} = cleanError(e) toast.show(clean || raw || e, { type: 'error', }) } }
const onToggleHide = () => requireAuth(() => { hidePromptControl.open() })
if (isAuthor || isPostHidden) { return null }
return ( <> <PostControlButton testID="postHideBtn" big={big} label={_(msg`Hide post`)} onPress={onToggleHide} hitSlop={hitSlop}> <PostControlButtonIcon icon={EyeSlash} /> </PostControlButton>
<Prompt.Basic control={hidePromptControl} title={_(msg`Hide this post?`)} description={_( msg`This post will be hidden from feeds and threads. This cannot be undone.`, )} onConfirm={onConfirmHide} confirmButtonCta={_(msg`Hide`)} /> </> )})