import {useState} from 'react' import {View} from 'react-native' import {Image} from 'expo-image' import {Trans} from '@lingui/macro' import {type LinkMeta} from '#/lib/link-meta/link-meta' import {toNiceDomain} from '#/lib/strings/url-helpers' import {LoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder' import {atoms as a, useTheme} from '#/alf' import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe' import {Image_Stroke2_Corner0_Rounded as ImageIcon} from '#/components/icons/Image' import {Text} from '#/components/Typography' export function LinkPreview({ linkMeta, loading, }: { linkMeta?: LinkMeta loading: boolean }) { const t = useTheme() const [imageLoadError, setImageLoadError] = useState(false) if (!linkMeta && !loading) { return null } return ( {linkMeta?.image && ( setImageLoadError(false)} onError={() => setImageLoadError(true)} /> )} {linkMeta && (!linkMeta.image || imageLoadError) && ( <> No image )} {linkMeta ? ( <> {linkMeta.title || linkMeta.url} {toNiceDomain(linkMeta.url)} ) : ( <> )} ) }