mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at verify-code 1.8 kB view raw
1import React from 'react' 2import {AppBskyActorGetProfile as GetProfile} from '@atproto/api' 3import {StyleProp, StyleSheet, TextStyle} from 'react-native' 4import {TextLinkOnWebOnly} from './Link' 5import {Text} from './text/Text' 6import {LoadingPlaceholder} from './LoadingPlaceholder' 7import {TypographyVariant} from 'lib/ThemeContext' 8import {sanitizeDisplayName} from 'lib/strings/display-names' 9import {sanitizeHandle} from 'lib/strings/handles' 10import {makeProfileLink} from 'lib/routes/links' 11import {useProfileQuery} from '#/state/queries/profile' 12import {STALE} from '#/state/queries' 13 14export function UserInfoText({ 15 type = 'md', 16 did, 17 attr, 18 failed, 19 prefix, 20 style, 21}: { 22 type?: TypographyVariant 23 did: string 24 attr?: keyof GetProfile.OutputSchema 25 loading?: string 26 failed?: string 27 prefix?: string 28 style?: StyleProp<TextStyle> 29}) { 30 attr = attr || 'handle' 31 failed = failed || 'user' 32 33 const {data: profile, isError} = useProfileQuery({ 34 did, 35 staleTime: STALE.INFINITY, 36 }) 37 38 let inner 39 if (isError) { 40 inner = ( 41 <Text type={type} style={style} numberOfLines={1}> 42 {failed} 43 </Text> 44 ) 45 } else if (profile) { 46 inner = ( 47 <TextLinkOnWebOnly 48 type={type} 49 style={style} 50 lineHeight={1.2} 51 numberOfLines={1} 52 href={makeProfileLink(profile)} 53 text={`${prefix || ''}${sanitizeDisplayName( 54 typeof profile[attr] === 'string' && profile[attr] 55 ? (profile[attr] as string) 56 : sanitizeHandle(profile.handle), 57 )}`} 58 /> 59 ) 60 } else { 61 inner = ( 62 <LoadingPlaceholder 63 width={80} 64 height={8} 65 style={styles.loadingPlaceholder} 66 /> 67 ) 68 } 69 70 return inner 71} 72 73const styles = StyleSheet.create({ 74 loadingPlaceholder: {position: 'relative', top: 1, left: 2}, 75})