From 48bd98f9ef1425a0642e8373af2afab857ded28e Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 16 Apr 2024 13:38:47 -0700 Subject: [PATCH] Use the existing `ExternalLinkEmbed` for embed previews in the composer (#3579) * use existing `ExternalLinkEmbed` for showing previews * cleanup --- src/view/com/composer/ExternalEmbed.tsx | 148 ++++++++++-------------- 1 file changed, 63 insertions(+), 85 deletions(-) diff --git a/src/view/com/composer/ExternalEmbed.tsx b/src/view/com/composer/ExternalEmbed.tsx index 02dd1bbd..3c2bf762 100644 --- a/src/view/com/composer/ExternalEmbed.tsx +++ b/src/view/com/composer/ExternalEmbed.tsx @@ -1,18 +1,15 @@ import React from 'react' -import { - ActivityIndicator, - StyleSheet, - TouchableOpacity, - View, -} from 'react-native' +import {TouchableOpacity, View} from 'react-native' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' -import {AutoSizedImage} from '../util/images/AutoSizedImage' -import {Text} from '../util/text/Text' -import {s} from 'lib/styles' -import {usePalette} from 'lib/hooks/usePalette' -import {ExternalEmbedDraft} from 'lib/api/index' -import {useLingui} from '@lingui/react' import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' + +import {ExternalEmbedDraft} from 'lib/api/index' +import {s} from 'lib/styles' +import {ExternalLinkEmbed} from 'view/com/util/post-embeds/ExternalLinkEmbed' +import {atoms as a, useTheme} from '#/alf' +import {Loader} from '#/components/Loader' +import {Text} from '#/components/Typography' export const ExternalEmbed = ({ link, @@ -21,50 +18,69 @@ export const ExternalEmbed = ({ link?: ExternalEmbedDraft onRemove: () => void }) => { - const pal = usePalette('default') - const palError = usePalette('error') + const t = useTheme() const {_} = useLingui() - if (!link) { - return - } + + const linkInfo = React.useMemo( + () => + link && { + title: link.meta?.title ?? link.uri, + uri: link.uri, + description: link.meta?.description ?? '', + thumb: link.localThumb?.path, + }, + [link], + ) + + if (!link) return null + return ( - + {link.isLoading ? ( - + style={[ + a.align_center, + a.justify_center, + a.py_5xl, + t.atoms.bg_contrast_25, + ]}> + - ) : link.localThumb ? ( - - ) : undefined} - - {!!link.meta?.title && ( - - {link.meta.title} + ) : link.meta?.error ? ( + + + {link.uri} - )} - - {link.uri} - - {!!link.meta?.description && ( - - {link.meta.description} - - )} - {link.meta?.error ? ( - + {link.meta.error} - ) : null} - + + ) : linkInfo ? ( + + + + ) : null} ) } - -const styles = StyleSheet.create({ - outer: { - borderWidth: 1, - borderRadius: 8, - marginTop: 20, - marginBottom: 10, - }, - inner: { - padding: 10, - }, - image: { - borderTopLeftRadius: 6, - borderTopRightRadius: 6, - width: '100%', - maxHeight: 200, - }, - removeBtn: { - position: 'absolute', - top: 10, - right: 10, - width: 36, - height: 36, - backgroundColor: 'rgba(0, 0, 0, 0.75)', - borderRadius: 18, - alignItems: 'center', - justifyContent: 'center', - }, - spinner: { - marginTop: 60, - }, - uri: { - marginTop: 2, - }, - description: { - marginTop: 4, - }, -})