[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.
This commit is contained in:
@@ -29,6 +29,7 @@ import {Link} from '#/components/Link'
|
|||||||
import {MediaInsetBorder} from '#/components/MediaInsetBorder'
|
import {MediaInsetBorder} from '#/components/MediaInsetBorder'
|
||||||
import {PublicationMetaRow} from '#/components/Post/Embed/StandardSiteEmbed/PublicationMetaRow'
|
import {PublicationMetaRow} from '#/components/Post/Embed/StandardSiteEmbed/PublicationMetaRow'
|
||||||
import {StandardSiteThemeProvider} from '#/components/Post/Embed/StandardSiteEmbed/StandardSiteThemeProvider'
|
import {StandardSiteThemeProvider} from '#/components/Post/Embed/StandardSiteEmbed/StandardSiteThemeProvider'
|
||||||
|
import {isStandardSitePublicationEmbed} from '#/components/Post/Embed/StandardSiteEmbed/utils'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {IS_NATIVE} from '#/env'
|
import {IS_NATIVE} from '#/env'
|
||||||
|
|
||||||
@@ -38,12 +39,6 @@ export type ThemeColors = {
|
|||||||
accentForeground: string
|
accentForeground: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isStandardSiteEmbed(view: AppBskyEmbedExternal.ViewExternal) {
|
|
||||||
return view.associatedRefs?.some(ref =>
|
|
||||||
new AtUri(ref.uri).collection.startsWith('site.standard.'),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useStandardSitePublisherConfig(
|
export function useStandardSitePublisherConfig(
|
||||||
view: AppBskyEmbedExternal.ViewExternal,
|
view: AppBskyEmbedExternal.ViewExternal,
|
||||||
) {
|
) {
|
||||||
@@ -102,11 +97,7 @@ export const StandardSiteEmbed = ({
|
|||||||
const isStandard = view.associatedRefs?.some(ref =>
|
const isStandard = view.associatedRefs?.some(ref =>
|
||||||
new AtUri(ref.uri).collection.startsWith('site.standard.'),
|
new AtUri(ref.uri).collection.startsWith('site.standard.'),
|
||||||
)
|
)
|
||||||
const isStandardPublication = view.associatedRefs?.every(
|
const isStandardPublication = isStandardSitePublicationEmbed(view)
|
||||||
ref =>
|
|
||||||
new AtUri(ref.uri).collection === 'site.standard.publication' &&
|
|
||||||
new AtUri(ref.uri).collection !== 'site.standard.document',
|
|
||||||
)
|
|
||||||
const themeColors = useMemo(() => {
|
const themeColors = useMemo(() => {
|
||||||
let custom = false
|
let custom = false
|
||||||
let accent = t.atoms.text.color
|
let accent = t.atoms.text.color
|
||||||
|
|||||||
@@ -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',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -22,10 +22,8 @@ import {useInteractionState} from '#/components/hooks/useInteractionState'
|
|||||||
import {GalleryBleed} from '#/components/images/Gallery'
|
import {GalleryBleed} from '#/components/images/Gallery'
|
||||||
import {ContentHider} from '#/components/moderation/ContentHider'
|
import {ContentHider} from '#/components/moderation/ContentHider'
|
||||||
import {PostAlerts} from '#/components/moderation/PostAlerts'
|
import {PostAlerts} from '#/components/moderation/PostAlerts'
|
||||||
import {
|
import {StandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed'
|
||||||
isStandardSiteEmbed,
|
import {isStandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed/utils'
|
||||||
StandardSiteEmbed,
|
|
||||||
} from '#/components/Post/Embed/StandardSiteEmbed'
|
|
||||||
import {RichText} from '#/components/RichText'
|
import {RichText} from '#/components/RichText'
|
||||||
import {Embed as StarterPackCard} from '#/components/StarterPack/StarterPackCard'
|
import {Embed as StarterPackCard} from '#/components/StarterPack/StarterPackCard'
|
||||||
import {SubtleHover} from '#/components/SubtleHover'
|
import {SubtleHover} from '#/components/SubtleHover'
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ import {Loader} from '#/components/Loader'
|
|||||||
import {ExternalEmbed} from '#/components/Post/Embed/ExternalEmbed'
|
import {ExternalEmbed} from '#/components/Post/Embed/ExternalEmbed'
|
||||||
import {ModeratedFeedEmbed} from '#/components/Post/Embed/FeedEmbed'
|
import {ModeratedFeedEmbed} from '#/components/Post/Embed/FeedEmbed'
|
||||||
import {ModeratedListEmbed} from '#/components/Post/Embed/ListEmbed'
|
import {ModeratedListEmbed} from '#/components/Post/Embed/ListEmbed'
|
||||||
import {
|
import {StandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed'
|
||||||
isStandardSiteEmbed,
|
import {isStandardSiteEmbed} from '#/components/Post/Embed/StandardSiteEmbed/utils'
|
||||||
StandardSiteEmbed,
|
|
||||||
} from '#/components/Post/Embed/StandardSiteEmbed'
|
|
||||||
import {Embed as StarterPackEmbed} from '#/components/StarterPack/StarterPackCard'
|
import {Embed as StarterPackEmbed} from '#/components/StarterPack/StarterPackCard'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {type Gif} from '#/features/gifPicker/types'
|
import {type Gif} from '#/features/gifPicker/types'
|
||||||
|
|||||||
Reference in New Issue
Block a user