Bluesky app fork with some witchin' additions 馃挮
witchsky.app
bluesky
fork
client
1import {type StyleProp, type TextStyle} from 'react-native'
2import {type AppBskyActorGetProfile} from '@atproto/api'
3
4import {makeProfileLink} from '#/lib/routes/links'
5import {sanitizeDisplayName} from '#/lib/strings/display-names'
6import {sanitizeHandle} from '#/lib/strings/handles'
7import {STALE} from '#/state/queries'
8import {useProfileQuery} from '#/state/queries/profile'
9import {atoms as a} from '#/alf'
10import {InlineLinkText} from '#/components/Link'
11import {Text} from '#/components/Typography'
12import {LoadingPlaceholder} from './LoadingPlaceholder'
13
14export function UserInfoText({
15 did,
16 attr,
17 failed,
18 prefix,
19 style,
20}: {
21 did: string
22 attr?: keyof AppBskyActorGetProfile.OutputSchema
23 loading?: string
24 failed?: string
25 prefix?: string
26 style?: StyleProp<TextStyle>
27}) {
28 attr = attr || 'handle'
29 failed = failed || 'user'
30
31 const {data: profile, isError} = useProfileQuery({
32 did,
33 staleTime: STALE.INFINITY,
34 })
35
36 if (isError) {
37 return (
38 <Text style={style} numberOfLines={1}>
39 {failed}
40 </Text>
41 )
42 } else if (profile) {
43 const text = `${prefix || ''}${sanitizeDisplayName(
44 typeof profile[attr] === 'string' && profile[attr]
45 ? (profile[attr] as string)
46 : sanitizeHandle(profile.handle),
47 )}`
48 return (
49 <InlineLinkText
50 label={text}
51 style={style}
52 numberOfLines={1}
53 to={makeProfileLink(profile)}>
54 <Text emoji style={style}>
55 {text}
56 </Text>
57 </InlineLinkText>
58 )
59 }
60
61 // eslint-disable-next-line bsky-internal/avoid-unwrapped-text
62 return (
63 <LoadingPlaceholder
64 width={80}
65 height={8}
66 style={[a.relative, {top: 1, left: 2}]}
67 />
68 )
69}