1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
import React from 'react'
import {
ActivityIndicator,
StyleSheet,
TouchableWithoutFeedback,
View,
} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {BlurView} from '../util/BlurView'
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'
export const ExternalEmbed = ({
link,
onRemove,
}: {
link?: ExternalEmbedDraft
onRemove: () => void
}) => {
const pal = usePalette('default')
const palError = usePalette('error')
if (!link) {
return <View />
}
return (
<View style={[styles.outer, pal.view, pal.border]}>
{link.isLoading ? (
<View
style={[styles.image, {backgroundColor: pal.colors.backgroundLight}]}>
<ActivityIndicator size="large" style={styles.spinner} />
</View>
) : link.localThumb ? (
<AutoSizedImage uri={link.localThumb.path} style={styles.image} />
) : undefined}
<View style={styles.inner}>
{!!link.meta?.title && (
<Text type="sm-bold" numberOfLines={2} style={[pal.text]}>
{link.meta.title}
</Text>
)}
<Text type="sm" numberOfLines={1} style={[pal.textLight, styles.uri]}>
{link.uri}
</Text>
{!!link.meta?.description && (
<Text
type="sm"
numberOfLines={2}
style={[pal.text, styles.description]}>
{link.meta.description}
</Text>
)}
{!!link.meta?.error && (
<Text
type="sm"
numberOfLines={2}
style={[{color: palError.colors.background}, styles.description]}>
{link.meta.error}
</Text>
)}
</View>
<TouchableWithoutFeedback onPress={onRemove}>
<BlurView style={styles.removeBtn} blurType="dark">
<FontAwesomeIcon size={18} icon="xmark" style={s.white} />
</BlurView>
</TouchableWithoutFeedback>
</View>
)
}
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,
borderRadius: 18,
alignItems: 'center',
justifyContent: 'center',
},
spinner: {
marginTop: 60,
},
uri: {
marginTop: 2,
},
description: {
marginTop: 4,
},
})
|