From 785fc26ec43547db5c97d9ddecb891d88bc737d6 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 22 May 2026 14:23:14 -0500 Subject: [PATCH] [APP-2160] Extract StandardSiteEmbed type guards into utils.ts Move isStandardSiteEmbed alongside a new isStandardSitePublicationEmbed helper. The publication check now requires at least one publication ref and zero document refs, replacing a tautological condition that also returned true for empty associatedRefs arrays. --- .../Post/Embed/StandardSiteEmbed/index.tsx | 13 ++---------- .../Post/Embed/StandardSiteEmbed/utils.ts | 20 +++++++++++++++++++ src/components/Post/Embed/index.tsx | 6 ++---- src/view/com/composer/ExternalEmbed.tsx | 6 ++---- 4 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 src/components/Post/Embed/StandardSiteEmbed/utils.ts diff --git a/src/components/Post/Embed/StandardSiteEmbed/index.tsx b/src/components/Post/Embed/StandardSiteEmbed/index.tsx index 64118fc26c..272b13e22d 100644 --- a/src/components/Post/Embed/StandardSiteEmbed/index.tsx +++ b/src/components/Post/Embed/StandardSiteEmbed/index.tsx @@ -29,6 +29,7 @@ import {Link} from '#/components/Link' import {MediaInsetBorder} from '#/components/MediaInsetBorder' import {PublicationMetaRow} from '#/components/Post/Embed/StandardSiteEmbed/PublicationMetaRow' import {StandardSiteThemeProvider} from '#/components/Post/Embed/StandardSiteEmbed/StandardSiteThemeProvider' +import {isStandardSitePublicationEmbed} from '#/components/Post/Embed/StandardSiteEmbed/utils' import {Text} from '#/components/Typography' import {IS_NATIVE} from '#/env' @@ -38,12 +39,6 @@ export type ThemeColors = { accentForeground: string } -export function isStandardSiteEmbed(view: AppBskyEmbedExternal.ViewExternal) { - return view.associatedRefs?.some(ref => - new AtUri(ref.uri).collection.startsWith('site.standard.'), - ) -} - export function useStandardSitePublisherConfig( view: AppBskyEmbedExternal.ViewExternal, ) { @@ -102,11 +97,7 @@ export const StandardSiteEmbed = ({ const isStandard = view.associatedRefs?.some(ref => new AtUri(ref.uri).collection.startsWith('site.standard.'), ) - const isStandardPublication = view.associatedRefs?.every( - ref => - new AtUri(ref.uri).collection === 'site.standard.publication' && - new AtUri(ref.uri).collection !== 'site.standard.document', - ) + const isStandardPublication = isStandardSitePublicationEmbed(view) const themeColors = useMemo(() => { let custom = false let accent = t.atoms.text.color diff --git a/src/components/Post/Embed/StandardSiteEmbed/utils.ts b/src/components/Post/Embed/StandardSiteEmbed/utils.ts new file mode 100644 index 0000000000..5985667e65 --- /dev/null +++ b/src/components/Post/Embed/StandardSiteEmbed/utils.ts @@ -0,0 +1,20 @@ +import {type AppBskyEmbedExternal, AtUri} from '@atproto/api' + +export function isStandardSiteEmbed(view: AppBskyEmbedExternal.ViewExternal) { + return view.associatedRefs?.some(ref => + new AtUri(ref.uri).collection.startsWith('site.standard.'), + ) +} + +export function isStandardSitePublicationEmbed( + view: AppBskyEmbedExternal.ViewExternal, +) { + return ( + view.associatedRefs?.some( + ref => new AtUri(ref.uri).collection === 'site.standard.publication', + ) && + view.associatedRefs.every( + ref => new AtUri(ref.uri).collection !== 'site.standard.document', + ) + ) +} diff --git a/src/components/Post/Embed/index.tsx b/src/components/Post/Embed/index.tsx index a2eed6a9cc..2114904557 100644 --- a/src/components/Post/Embed/index.tsx +++ b/src/components/Post/Embed/index.tsx @@ -22,10 +22,8 @@ import {useInteractionState} from '#/components/hooks/useInteractionState' import {GalleryBleed} from '#/components/images/Gallery' import {ContentHider} from '#/components/moderation/ContentHider' import {PostAlerts} from '#/components/moderation/PostAlerts' -import { - isStandardSiteEmbed, - StandardSiteEmbed, -} from '#/components/Post/Embed/StandardSiteEmbed' +import {StandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed' +import {isStandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed/utils' import {RichText} from '#/components/RichText' import {Embed as StarterPackCard} from '#/components/StarterPack/StarterPackCard' import {SubtleHover} from '#/components/SubtleHover' diff --git a/src/view/com/composer/ExternalEmbed.tsx b/src/view/com/composer/ExternalEmbed.tsx index 612f08d6bf..272d09bab6 100644 --- a/src/view/com/composer/ExternalEmbed.tsx +++ b/src/view/com/composer/ExternalEmbed.tsx @@ -12,10 +12,8 @@ import {Loader} from '#/components/Loader' import {ExternalEmbed} from '#/components/Post/Embed/ExternalEmbed' import {ModeratedFeedEmbed} from '#/components/Post/Embed/FeedEmbed' import {ModeratedListEmbed} from '#/components/Post/Embed/ListEmbed' -import { - isStandardSiteEmbed, - StandardSiteEmbed, -} from '#/components/Post/Embed/StandardSiteEmbed' +import {StandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed' +import {isStandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed/utils' import {Embed as StarterPackEmbed} from '#/components/StarterPack/StarterPackCard' import {Text} from '#/components/Typography' import {type Gif} from '#/features/gifPicker/types'