From c5c3ce7f04bea821ad0125bb069244c31052c7b0 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 7 Aug 2024 14:38:39 -0500 Subject: [PATCH] Only load threadgate for threads --- src/view/com/post-thread/PostThreadItem.tsx | 2 ++ src/view/com/util/forms/PostDropdownBtn.tsx | 12 ++++++------ src/view/com/util/post-ctrls/PostCtrls.tsx | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index fc14290070..55c67befc9 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -411,6 +411,7 @@ let PostThreadItemLoaded = ({ onPressReply={onPressReply} logContext="PostThreadItem" rootPostUri={rootUri} + threadgateRecord={threadgateRecord ?? undefined} /> @@ -564,6 +565,7 @@ let PostThreadItemLoaded = ({ onPressReply={onPressReply} logContext="PostThreadItem" rootPostUri={rootUri} + threadgateRecord={threadgateRecord ?? undefined} /> diff --git a/src/view/com/util/forms/PostDropdownBtn.tsx b/src/view/com/util/forms/PostDropdownBtn.tsx index bfdf9b168d..1319bc9aff 100644 --- a/src/view/com/util/forms/PostDropdownBtn.tsx +++ b/src/view/com/util/forms/PostDropdownBtn.tsx @@ -9,6 +9,7 @@ import * as Clipboard from 'expo-clipboard' import { AppBskyFeedDefs, AppBskyFeedPost, + AppBskyFeedThreadgate, AtUri, RichText as RichTextAPI, } from '@atproto/api' @@ -34,7 +35,6 @@ import { import {useToggleQuoteDetachmentMutation} from '#/state/queries/postgate' import {getMaybeDetachedQuoteEmbed} from '#/state/queries/postgate/util' import {useToggleReplyVisibilityMutation} from '#/state/queries/threadgate' -import {useThreadgateRecordQuery} from '#/state/queries/threadgate' import {useSession} from '#/state/session' import {getCurrentRoute} from 'lib/routes/helpers' import {shareUrl} from 'lib/sharing' @@ -80,6 +80,7 @@ let PostDropdownBtn = ({ size, timestamp, rootPostUri, + threadgateRecord, }: { testID: string post: Shadow @@ -91,6 +92,7 @@ let PostDropdownBtn = ({ size?: 'lg' | 'md' | 'sm' timestamp: string rootPostUri?: string + threadgateRecord?: AppBskyFeedThreadgate.Record }): React.ReactNode => { const {hasSession, currentAccount} = useSession() const theme = useTheme() @@ -134,11 +136,8 @@ let PostDropdownBtn = ({ ) const isPostHidden = hiddenPosts && hiddenPosts.includes(postUri) const isAuthor = postAuthor.did === currentAccount?.did - - const {data: threadgate} = useThreadgateRecordQuery({ - postUri: rootUri, - }) - const isReplyHiddenByThreadgate = threadgate?.hiddenReplies?.includes(postUri) + const isReplyHiddenByThreadgate = + threadgateRecord?.hiddenReplies?.includes(postUri) const {mutateAsync: toggleQuoteDetachment, isPending} = useToggleQuoteDetachmentMutation() @@ -270,6 +269,7 @@ let PostDropdownBtn = ({ ) const onToggleReplyVisibility = React.useCallback(async () => { + // TODO no threadgate? if (!rootPostUri) return const action = isReplyHiddenByThreadgate ? 'show' : 'hide' diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index c6e2dd1c51..5a3db2ac19 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -10,6 +10,7 @@ import * as Clipboard from 'expo-clipboard' import { AppBskyFeedDefs, AppBskyFeedPost, + AppBskyFeedThreadgate, AtUri, RichText as RichTextAPI, } from '@atproto/api' @@ -60,6 +61,7 @@ let PostCtrls = ({ onPressReply, logContext, rootPostUri, + threadgateRecord, }: { big?: boolean post: Shadow @@ -70,6 +72,7 @@ let PostCtrls = ({ onPressReply: () => void logContext: 'FeedItem' | 'PostThreadItem' | 'Post' rootPostUri?: string + threadgateRecord?: AppBskyFeedThreadgate.Record }): React.ReactNode => { const t = useTheme() const {_} = useLingui() @@ -341,6 +344,7 @@ let PostCtrls = ({ hitSlop={POST_CTRL_HITSLOP} timestamp={post.indexedAt} rootPostUri={rootPostUri} + threadgateRecord={threadgateRecord} /> {gate('debug_show_feedcontext') && feedContext && (