Tune up the link card to look nicer, show more info, and layout horizontally on web to user space more nicely (#1190)

zio/stable
Paul Frazee 2023-08-16 10:02:41 -07:00 committed by GitHub
parent 884e5c9294
commit 79a6819769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 17 deletions

View File

@ -30,7 +30,7 @@ export function toNiceDomain(url: string): string {
if (`https://${urlp.host}` === PROD_SERVICE) { if (`https://${urlp.host}` === PROD_SERVICE) {
return 'Bluesky Social' return 'Bluesky Social'
} }
return urlp.host return urlp.host ? urlp.host : url
} catch (e) { } catch (e) {
return url return url
} }

View File

@ -4,6 +4,8 @@ import {Text} from '../text/Text'
import {StyleSheet, View} from 'react-native' import {StyleSheet, View} from 'react-native'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {AppBskyEmbedExternal} from '@atproto/api' import {AppBskyEmbedExternal} from '@atproto/api'
import {isDesktopWeb} from 'platform/detection'
import {toNiceDomain} from 'lib/strings/url-helpers'
export const ExternalLinkEmbed = ({ export const ExternalLinkEmbed = ({
link, link,
@ -14,7 +16,7 @@ export const ExternalLinkEmbed = ({
}) => { }) => {
const pal = usePalette('default') const pal = usePalette('default')
return ( return (
<> <View style={styles.extContainer}>
{link.thumb ? ( {link.thumb ? (
<View style={styles.extImageContainer}> <View style={styles.extImageContainer}>
<Image <Image
@ -26,39 +28,56 @@ export const ExternalLinkEmbed = ({
</View> </View>
) : undefined} ) : undefined}
<View style={styles.extInner}> <View style={styles.extInner}>
<Text type="md-bold" numberOfLines={2} style={[pal.text]}>
{link.title || link.uri}
</Text>
<Text <Text
type="sm" type="sm"
numberOfLines={1} numberOfLines={1}
style={[pal.textLight, styles.extUri]}> style={[pal.textLight, styles.extUri]}>
{link.uri} {toNiceDomain(link.uri)}
</Text>
<Text
type={isDesktopWeb ? 'xl-bold' : 'lg-bold'}
numberOfLines={isDesktopWeb ? 2 : 4}
style={[pal.text]}>
{link.title || link.uri}
</Text> </Text>
{link.description ? ( {link.description ? (
<Text <Text
type="sm" type={isDesktopWeb ? 'lg' : 'md'}
numberOfLines={2} numberOfLines={isDesktopWeb ? 2 : 4}
style={[pal.text, styles.extDescription]}> style={[pal.text, styles.extDescription]}>
{link.description} {link.description}
</Text> </Text>
) : undefined} ) : undefined}
</View> </View>
</> </View>
) )
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
extContainer: {
flexDirection: isDesktopWeb ? 'row' : 'column',
},
extInner: { extInner: {
padding: 10, paddingHorizontal: isDesktopWeb ? 14 : 10,
}, paddingTop: 8,
extImageContainer: { paddingBottom: 10,
borderTopLeftRadius: 6, flex: isDesktopWeb ? 1 : undefined,
borderTopRightRadius: 6,
width: '100%',
height: 200,
overflow: 'hidden',
}, },
extImageContainer: isDesktopWeb
? {
borderTopLeftRadius: 6,
borderBottomLeftRadius: 6,
width: 120,
aspectRatio: 1,
overflow: 'hidden',
}
: {
borderTopLeftRadius: 6,
borderTopRightRadius: 6,
width: '100%',
height: 200,
overflow: 'hidden',
},
extImage: { extImage: {
width: '100%', width: '100%',
height: 200, height: 200,