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

240 lines
6.7 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'
2020-12-13 14:04:25 +01:00
import ParseContent from '@components/ParseContent'
import { useTheme } from '@utils/styles/ThemeManager'
import { StyleConstants } from '@utils/styles/constants'
2020-11-30 00:24:53 +01:00
import { useTranslation } from 'react-i18next'
2020-12-13 14:04:25 +01:00
import Emojis from '@components/Timelines/Timeline/Shared/Emojis'
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)
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-12-01 00:44:28 +01:00
<View style={styles.display_name}>
{account?.emojis ? (
<Emojis
content={account?.display_name || account?.username}
emojis={account.emojis}
size={StyleConstants.Font.Size.L}
fontBold={true}
/>
) : (
<Text
style={{
color: theme.primary,
fontSize: StyleConstants.Font.Size.L,
fontWeight: StyleConstants.Font.Weight.Bold
}}
>
{account?.display_name || account?.username}
</Text>
2020-11-22 00:46:23 +01:00
)}
2020-12-01 00:44:28 +01:00
</View>
2020-11-23 00:07:32 +01:00
2020-12-01 00:44:28 +01:00
<View style={styles.account}>
<Text
style={{
color: theme.secondary,
fontSize: StyleConstants.Font.Size.M
}}
selectable
>
@{account?.acct}
</Text>
{account?.locked && (
<Feather
name='lock'
style={styles.account_types}
color={theme.secondary}
/>
)}
{account?.bot && (
<Feather
name='hard-drive'
style={styles.account_types}
color={theme.secondary}
/>
)}
</View>
2020-11-22 00:46:23 +01:00
2020-12-01 00:44:28 +01:00
{account?.fields && account.fields.length > 0 && (
<View style={[styles.fields, { borderTopColor: theme.border }]}>
2020-11-23 00:07:32 +01:00
{account.fields.map((field, index) => (
2020-12-01 00:44:28 +01:00
<View
key={index}
style={[styles.field, { borderBottomColor: theme.border }]}
>
<View
2020-11-23 00:07:32 +01:00
style={{
2020-12-01 00:44:28 +01:00
flexBasis: '30%',
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderRightColor: theme.border,
paddingLeft: StyleConstants.Spacing.S,
paddingRight: StyleConstants.Spacing.S
2020-11-23 00:07:32 +01:00
}}
>
<ParseContent
content={field.name}
2020-12-13 01:24:25 +01:00
size={'M'}
2020-11-23 00:07:32 +01:00
emojis={account.emojis}
showFullLink
2020-12-01 00:44:28 +01:00
/>
{field.verified_at && (
<Feather
name='check-circle'
size={StyleConstants.Font.Size.M}
color={theme.primary}
/>
)}
</View>
<View
style={{
flexBasis: '70%',
alignItems: 'center',
justifyContent: 'center',
paddingLeft: StyleConstants.Spacing.S,
paddingRight: StyleConstants.Spacing.S
}}
>
2020-11-23 00:07:32 +01:00
<ParseContent
content={field.value}
2020-12-13 01:24:25 +01:00
size={'M'}
2020-11-23 00:07:32 +01:00
emojis={account.emojis}
showFullLink
/>
2020-12-01 00:44:28 +01:00
</View>
2020-11-23 00:07:32 +01:00
</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-12-13 01:24:25 +01:00
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-12-01 00:44:28 +01:00
<View style={styles.created_at}>
<Feather
name='calendar'
size={StyleConstants.Font.Size.M + 2}
color={theme.secondary}
style={styles.created_at_icon}
/>
<Text
style={{
color: theme.secondary,
fontSize: StyleConstants.Font.Size.M
}}
>
{t(
'content.created_at',
{
date: new Date(account?.created_at!).toLocaleDateString('zh-CN', {
2020-11-30 00:24:53 +01:00
year: 'numeric',
month: 'long',
day: 'numeric'
})
2020-12-01 00:44:28 +01:00
} || null
)}
</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', {
2020-12-01 00:44:28 +01:00
count: account?.statuses_count || 0
2020-11-30 00:24:53 +01:00
})}
2020-11-23 00:07:32 +01:00
</Text>
2020-12-01 00:44:28 +01:00
<Text style={{ color: theme.primary, textAlign: 'center' }}>
2020-11-30 00:24:53 +01:00
{t('content.summary.followers_count', {
2020-12-01 00:44:28 +01:00
count: account?.followers_count || 0
2020-11-30 00:24:53 +01:00
})}
2020-11-23 00:07:32 +01:00
</Text>
2020-12-01 00:44:28 +01:00
<Text style={{ color: theme.primary, textAlign: 'right' }}>
2020-11-30 00:24:53 +01:00
{t('content.summary.following_count', {
2020-12-01 00:44:28 +01:00
count: account?.following_count || 0
2020-11-30 00:24:53 +01:00
})}
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-12-01 00:44:28 +01:00
flexDirection: 'row',
2020-11-30 00:24:53 +01:00
marginTop: StyleConstants.Spacing.M,
marginBottom: StyleConstants.Spacing.XS
2020-11-22 00:46:23 +01:00
},
account: {
2020-12-01 00:44:28 +01:00
flexDirection: 'row',
alignItems: 'center',
marginBottom: StyleConstants.Spacing.L
2020-11-23 00:07:32 +01:00
},
2020-12-01 00:44:28 +01:00
account_types: { marginLeft: StyleConstants.Spacing.S },
2020-11-23 00:07:32 +01:00
fields: {
2020-12-03 22:03:06 +01:00
borderTopWidth: StyleSheet.hairlineWidth,
2020-12-01 00:44:28 +01:00
marginBottom: StyleConstants.Spacing.M
},
field: {
flex: 1,
flexDirection: 'row',
2020-12-03 22:03:06 +01:00
borderBottomWidth: StyleSheet.hairlineWidth,
2020-12-01 00:44:28 +01:00
paddingTop: StyleConstants.Spacing.S,
paddingBottom: StyleConstants.Spacing.S
2020-11-23 00:07:32 +01:00
},
note: {
2020-12-01 00:44:28 +01:00
marginBottom: StyleConstants.Spacing.L
2020-11-23 00:07:32 +01:00
},
created_at: {
flexDirection: 'row',
2020-12-01 00:44:28 +01:00
alignItems: 'center',
2020-11-30 00:24:53 +01:00
marginBottom: StyleConstants.Spacing.M
2020-11-23 00:07:32 +01:00
},
2020-12-01 00:44:28 +01:00
created_at_icon: {
marginRight: StyleConstants.Spacing.XS
},
2020-11-23 00:07:32 +01:00
summary: {
2020-12-01 00:44:28 +01:00
flex: 1,
2020-11-23 00:07:32 +01:00
flexDirection: 'row',
justifyContent: 'space-between'
2020-11-22 00:46:23 +01:00
}
})
export default AccountInformation