import React from 'react' import {type StyleProp, View, type ViewStyle} from 'react-native' import {cleanError} from '#/lib/strings/errors' import { useResolveGifQuery, useResolveLinkQuery, } from '#/state/queries/resolve-link' import {type Gif} from '#/state/queries/tenor' import {ExternalEmbedRemoveBtn} from '#/view/com/composer/ExternalEmbedRemoveBtn' import {atoms as a, useTheme} from '#/alf' 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 {Embed as StarterPackEmbed} from '#/components/StarterPack/StarterPackCard' import {Text} from '#/components/Typography' export const ExternalEmbedGif = ({ onRemove, gif, }: { onRemove: () => void gif: Gif }) => { const t = useTheme() const {data, error} = useResolveGifQuery(gif) const linkInfo = React.useMemo( () => data && { title: data.title ?? data.uri, uri: data.uri, description: data.description ?? '', thumb: data.thumb?.source.path, }, [data], ) const loadingStyle: ViewStyle = { aspectRatio: gif.media_formats.gif.dims[0] / gif.media_formats.gif.dims[1], width: '100%', } return ( {linkInfo ? ( ) : error ? ( {gif.url} {cleanError(error)} ) : ( )} ) } export const ExternalEmbedLink = ({ uri, hasQuote, onRemove, }: { uri: string hasQuote: boolean onRemove: () => void }) => { const t = useTheme() const {data, error} = useResolveLinkQuery(uri) const linkComponent = React.useMemo(() => { if (data) { if (data.type === 'external') { return ( ) } else if (data.kind === 'feed') { return ( ) } else if (data.kind === 'list') { return ( ) } else if (data.kind === 'starter-pack') { return } } }, [data, uri]) if (data?.type === 'record' && hasQuote) { // This is not currently supported by the data model so don't preview it. return null } return ( {linkComponent ? ( {linkComponent} ) : error ? ( {uri} {cleanError(error)} ) : ( )} ) } function Container({ style, children, }: { style?: StyleProp children: React.ReactNode }) { const t = useTheme() return ( {children} ) }