From a18b25d16c7ff4e5233cc6ca45511ba42b12f55f Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 20 May 2025 18:49:20 +0300 Subject: [Live] Add warning if link is missing image (#8393) --- src/components/live/LinkPreview.tsx | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/components/live/LinkPreview.tsx (limited to 'src/components/live/LinkPreview.tsx') diff --git a/src/components/live/LinkPreview.tsx b/src/components/live/LinkPreview.tsx new file mode 100644 index 000000000..98320a9e8 --- /dev/null +++ b/src/components/live/LinkPreview.tsx @@ -0,0 +1,98 @@ +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)} + + + + ) : ( + <> + + + + )} + + + ) +} -- cgit 1.4.1