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

116 lines
3.4 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
2021-01-04 18:29:02 +01:00
import { useNavigation } from '@react-navigation/native'
2021-01-24 02:25:43 +01:00
import { StackNavigationProp } from '@react-navigation/stack'
2020-12-27 16:25:29 +01:00
import { StyleConstants } from '@root/utils/styles/constants'
import { useTheme } from '@root/utils/styles/ThemeManager'
2021-01-23 02:41:50 +01:00
import React from 'react'
2020-12-27 16:25:29 +01:00
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, View } from 'react-native'
2021-01-23 02:41:50 +01:00
import { PlaceholderLine } from 'rn-placeholder'
2020-12-27 16:25:29 +01:00
export interface Props {
account: Mastodon.Account | undefined
2021-01-24 02:25:43 +01:00
myInfo: boolean
2020-12-27 16:25:29 +01:00
}
2021-01-24 02:25:43 +01:00
const AccountInformationStats: React.FC<Props> = ({ account, myInfo }) => {
const navigation = useNavigation<
2021-01-30 01:29:15 +01:00
StackNavigationProp<Nav.TabLocalStackParamList>
2021-01-24 02:25:43 +01:00
>()
2020-12-27 16:25:29 +01:00
const { theme } = useTheme()
const { t } = useTranslation('sharedAccount')
return (
2021-01-23 02:41:50 +01:00
<View style={[styles.stats, { flexDirection: 'row' }]}>
{account ? (
<Text
style={[styles.stat, { color: theme.primaryDefault }]}
2021-01-23 02:41:50 +01:00
children={t('content.summary.statuses_count', {
count: account.statuses_count || 0
2020-12-27 16:25:29 +01:00
})}
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('account_stats_toots_press', {
count: account.statuses_count
})
2021-01-30 01:29:15 +01:00
myInfo && navigation.push('Tab-Shared-Account', { account })
2021-01-24 02:25:43 +01:00
}}
2021-01-23 02:41:50 +01:00
/>
) : (
<PlaceholderLine
width={StyleConstants.Font.Size.S * 1.25}
height={StyleConstants.Font.LineHeight.S}
color={theme.shimmerDefault}
noMargin
style={{ borderRadius: 0 }}
/>
)}
{account ? (
2020-12-27 16:25:29 +01:00
<Text
style={[styles.stat, { color: theme.primaryDefault, textAlign: 'right' }]}
2021-01-23 02:41:50 +01:00
children={t('content.summary.following_count', {
2021-03-15 00:18:44 +01:00
count: account.following_count
2021-01-23 02:41:50 +01:00
})}
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('account_stats_following_press', {
count: account.following_count
})
2021-03-15 00:18:44 +01:00
navigation.push('Tab-Shared-Users', {
reference: 'accounts',
id: account.id,
type: 'following',
count: account.following_count
2021-01-04 18:29:02 +01:00
})
2021-01-24 02:25:43 +01:00
}}
2021-01-23 02:41:50 +01:00
/>
) : (
<PlaceholderLine
width={StyleConstants.Font.Size.S * 1.25}
height={StyleConstants.Font.LineHeight.S}
color={theme.shimmerDefault}
noMargin
style={{ borderRadius: 0 }}
/>
)}
{account ? (
2020-12-27 16:25:29 +01:00
<Text
style={[styles.stat, { color: theme.primaryDefault, textAlign: 'center' }]}
2021-01-23 02:41:50 +01:00
children={t('content.summary.followers_count', {
2021-03-15 00:18:44 +01:00
count: account.followers_count
2021-01-23 02:41:50 +01:00
})}
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('account_stats_followers_press', {
count: account.followers_count
})
2021-03-15 00:18:44 +01:00
navigation.push('Tab-Shared-Users', {
reference: 'accounts',
id: account.id,
type: 'followers',
count: account.followers_count
2021-01-04 18:29:02 +01:00
})
2021-01-24 02:25:43 +01:00
}}
2021-01-23 02:41:50 +01:00
/>
) : (
<PlaceholderLine
width={StyleConstants.Font.Size.S * 1.25}
height={StyleConstants.Font.LineHeight.S}
color={theme.shimmerDefault}
noMargin
style={{ borderRadius: 0 }}
/>
)}
2020-12-27 16:25:29 +01:00
</View>
)
2021-01-23 02:41:50 +01:00
}
2020-12-27 16:25:29 +01:00
const styles = StyleSheet.create({
stats: {
flex: 1,
justifyContent: 'space-between'
},
stat: {
...StyleConstants.FontStyle.S
2020-12-27 16:25:29 +01:00
}
})
export default AccountInformationStats