mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {StyleSheet, View} from 'react-native'
3import {Text} from './text/Text'
4import {DesktopWebTextLink} from './Link'
5import {niceDate} from 'lib/strings/time'
6import {usePalette} from 'lib/hooks/usePalette'
7import {UserAvatar} from './UserAvatar'
8import {observer} from 'mobx-react-lite'
9import {sanitizeDisplayName} from 'lib/strings/display-names'
10import {sanitizeHandle} from 'lib/strings/handles'
11import {isAndroid} from 'platform/detection'
12import {TimeElapsed} from './TimeElapsed'
13import {makeProfileLink} from 'lib/routes/links'
14
15interface PostMetaOpts {
16 author: {
17 avatar?: string
18 did: string
19 handle: string
20 displayName?: string | undefined
21 }
22 showAvatar?: boolean
23 authorHasWarning: boolean
24 postHref: string
25 timestamp: string
26}
27
28export const PostMeta = observer(function (opts: PostMetaOpts) {
29 const pal = usePalette('default')
30 const displayName = opts.author.displayName || opts.author.handle
31 const handle = opts.author.handle
32
33 return (
34 <View style={styles.metaOneLine}>
35 {opts.showAvatar && typeof opts.author.avatar !== 'undefined' && (
36 <View style={styles.avatar}>
37 <UserAvatar
38 avatar={opts.author.avatar}
39 size={16}
40 // TODO moderation
41 />
42 </View>
43 )}
44 <View style={styles.maxWidth}>
45 <DesktopWebTextLink
46 type="lg-bold"
47 style={pal.text}
48 numberOfLines={1}
49 lineHeight={1.2}
50 text={
51 <>
52 {sanitizeDisplayName(displayName)}
53 <Text
54 type="md"
55 numberOfLines={1}
56 lineHeight={1.2}
57 style={pal.textLight}>
58 {sanitizeHandle(handle, '@')}
59 </Text>
60 </>
61 }
62 href={makeProfileLink(opts.author)}
63 />
64 </View>
65 {!isAndroid && (
66 <Text
67 type="md"
68 style={pal.textLight}
69 lineHeight={1.2}
70 accessible={false}>
71 ·
72 </Text>
73 )}
74 <TimeElapsed timestamp={opts.timestamp}>
75 {({timeElapsed}) => (
76 <DesktopWebTextLink
77 type="md"
78 style={pal.textLight}
79 lineHeight={1.2}
80 text={timeElapsed}
81 accessibilityLabel={niceDate(opts.timestamp)}
82 accessibilityHint=""
83 href={opts.postHref}
84 />
85 )}
86 </TimeElapsed>
87 </View>
88 )
89})
90
91const styles = StyleSheet.create({
92 metaOneLine: {
93 flexDirection: 'row',
94 alignItems: 'baseline',
95 paddingBottom: 2,
96 gap: 4,
97 },
98 avatar: {
99 alignSelf: 'center',
100 },
101 maxWidth: {
102 flex: isAndroid ? 1 : undefined,
103 maxWidth: !isAndroid ? '80%' : undefined,
104 },
105})