tooot/src/screens/Shared/Account/Information.tsx

165 lines
4.8 KiB
TypeScript
Raw Normal View History

2020-11-22 00:46:23 +01:00
import React, { useState } from 'react'
import { Image, StyleSheet, Text, View } from 'react-native'
import ShimmerPlaceholder from 'react-native-shimmer-placeholder'
import { Feather } from '@expo/vector-icons'
import ParseContent from 'src/components/ParseContent'
2020-11-23 00:07:32 +01:00
import { useTheme } from 'src/utils/styles/ThemeManager'
2020-11-30 00:24:53 +01:00
import { StyleConstants } from 'src/utils/styles/constants'
import { useTranslation } from 'react-i18next'
2020-11-22 00:46:23 +01:00
export interface Props {
account: Mastodon.Account | undefined
}
const AccountInformation: React.FC<Props> = ({ account }) => {
2020-11-30 00:24:53 +01:00
const { t } = useTranslation('sharedAccount')
2020-11-23 00:07:32 +01:00
const { theme } = useTheme()
2020-11-22 00:46:23 +01:00
const [avatarLoaded, setAvatarLoaded] = useState(false)
// add emoji support
return (
<View style={styles.information}>
{/* <Text>Moved or not: {account.moved}</Text> */}
<ShimmerPlaceholder visible={avatarLoaded} width={90} height={90}>
<Image
source={{ uri: account?.avatar }}
style={styles.avatar}
onLoadEnd={() => setAvatarLoaded(true)}
/>
</ShimmerPlaceholder>
2020-11-23 00:07:32 +01:00
<Text style={[styles.display_name, { color: theme.primary }]}>
2020-11-22 00:46:23 +01:00
{account?.display_name || account?.username}
{account?.bot && (
<Feather name='hard-drive' style={styles.display_name} />
)}
</Text>
2020-11-23 00:07:32 +01:00
<Text style={[styles.account, { color: theme.secondary }]}>
@{account?.acct}
2020-11-22 00:46:23 +01:00
{account?.locked && <Feather name='lock' />}
</Text>
2020-11-23 00:07:32 +01:00
{account?.fields && (
<View style={styles.fields}>
{account.fields.map((field, index) => (
<View key={index} style={{ flex: 1, flexDirection: 'row' }}>
<Text
style={{
width: '30%',
alignSelf: 'center',
color: theme.primary
}}
>
<ParseContent
content={field.name}
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.M}
2020-11-23 00:07:32 +01:00
emojis={account.emojis}
showFullLink
/>{' '}
{field.verified_at && <Feather name='check-circle' />}
</Text>
<Text style={{ width: '70%', color: theme.primary }}>
<ParseContent
content={field.value}
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.M}
2020-11-23 00:07:32 +01:00
emojis={account.emojis}
showFullLink
/>
</Text>
</View>
))}
</View>
)}
2020-11-22 00:46:23 +01:00
{account?.note && (
2020-11-23 00:07:32 +01:00
<View style={styles.note}>
<ParseContent
content={account.note}
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.M}
2020-11-23 00:07:32 +01:00
emojis={account.emojis}
/>
</View>
2020-11-22 00:46:23 +01:00
)}
2020-11-23 00:07:32 +01:00
2020-11-22 00:46:23 +01:00
{account?.created_at && (
2020-11-23 00:07:32 +01:00
<View style={styles.created_at}>
2020-11-30 00:24:53 +01:00
<Feather name='calendar' size={StyleConstants.Font.Size.M + 2} />
2020-11-23 00:07:32 +01:00
<Text
style={{
color: theme.primary,
2020-11-30 00:24:53 +01:00
fontSize: StyleConstants.Font.Size.M,
marginLeft: StyleConstants.Spacing.XS
2020-11-23 00:07:32 +01:00
}}
>
2020-11-30 00:24:53 +01:00
{t('content.created_at', {
date: new Date(account.created_at).toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
2020-11-23 00:07:32 +01:00
})}
</Text>
</View>
2020-11-22 00:46:23 +01:00
)}
2020-11-23 00:07:32 +01:00
<View style={styles.summary}>
<Text style={{ color: theme.primary }}>
2020-11-30 00:24:53 +01:00
{t('content.summary.statuses_count', {
count: account?.statuses_count
})}
2020-11-23 00:07:32 +01:00
</Text>
<Text style={{ color: theme.primary }}>
2020-11-30 00:24:53 +01:00
{t('content.summary.followers_count', {
count: account?.followers_count
})}
2020-11-23 00:07:32 +01:00
</Text>
<Text style={{ color: theme.primary }}>
2020-11-30 00:24:53 +01:00
{t('content.summary.following_count', {
count: account?.following_count
})}
2020-11-23 00:07:32 +01:00
</Text>
</View>
2020-11-22 00:46:23 +01:00
</View>
)
}
const styles = StyleSheet.create({
2020-11-23 00:07:32 +01:00
information: {
2020-11-30 00:24:53 +01:00
marginTop: -30 - StyleConstants.Spacing.Global.PagePadding,
padding: StyleConstants.Spacing.Global.PagePadding
2020-11-23 00:07:32 +01:00
},
2020-11-22 00:46:23 +01:00
avatar: {
2020-11-30 00:24:53 +01:00
width: StyleConstants.Avatar.L,
height: StyleConstants.Avatar.L,
2020-11-23 00:07:32 +01:00
borderRadius: 8
2020-11-22 00:46:23 +01:00
},
display_name: {
2020-11-30 00:24:53 +01:00
fontSize: StyleConstants.Font.Size.L,
fontWeight: StyleConstants.Font.Weight.Bold,
marginTop: StyleConstants.Spacing.M,
marginBottom: StyleConstants.Spacing.XS
2020-11-22 00:46:23 +01:00
},
account: {
2020-11-30 00:24:53 +01:00
fontSize: StyleConstants.Font.Size.M,
marginBottom: StyleConstants.Spacing.S
2020-11-23 00:07:32 +01:00
},
fields: {
2020-11-30 00:24:53 +01:00
marginBottom: StyleConstants.Spacing.S
2020-11-23 00:07:32 +01:00
},
note: {
2020-11-30 00:24:53 +01:00
marginBottom: StyleConstants.Spacing.M
2020-11-23 00:07:32 +01:00
},
created_at: {
flexDirection: 'row',
2020-11-30 00:24:53 +01:00
marginBottom: StyleConstants.Spacing.M
2020-11-23 00:07:32 +01:00
},
summary: {
flexDirection: 'row',
justifyContent: 'space-between'
2020-11-22 00:46:23 +01:00
}
})
export default AccountInformation