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

92 lines
2.9 KiB
TypeScript
Raw Normal View History

import Icon from '@components/Icon'
import CustomText from '@components/Text'
import { useRelationshipQuery } from '@utils/queryHooks/relationship'
2022-12-12 20:43:45 +01:00
import { getInstanceAccount, getInstanceUri } from '@utils/slices/instancesSlice'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { View } from 'react-native'
2021-01-20 00:39:39 +01:00
import { useSelector } from 'react-redux'
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
}
2022-12-12 20:43:45 +01:00
const AccountInformationAccount: React.FC<Props> = ({ account }) => {
const { t } = useTranslation('screenTabs')
2022-02-12 14:51:01 +01:00
const { colors } = useTheme()
2022-12-12 20:43:45 +01:00
const instanceAccount = useSelector(getInstanceAccount, (prev, next) => prev?.acct === next?.acct)
2021-02-20 19:12:44 +01:00
const instanceUri = useSelector(getInstanceUri)
2020-12-27 16:25:29 +01:00
const { data: relationship } = useRelationshipQuery({
id: account?.id || '',
options: { enabled: account !== undefined }
})
2022-12-12 20:43:45 +01:00
const localInstance = instanceAccount.acct.includes('@')
? instanceAccount.acct.includes(`@${instanceUri}`)
: true
2021-05-09 21:59:03 +02:00
if (account || (localInstance && instanceAccount)) {
2020-12-27 16:25:29 +01:00
return (
2021-01-23 02:41:50 +01:00
<View
style={{
flexDirection: 'row',
alignItems: 'center',
borderRadius: 0,
marginBottom: StyleConstants.Spacing.L
}}
2020-12-27 16:25:29 +01:00
>
<CustomText fontStyle='M' style={{ color: colors.secondary }}>
{account?.moved ? (
<>
{' '}
<CustomText selectable>@{account.moved.acct}</CustomText>
</>
) : null}
<CustomText
style={{
2022-12-12 20:43:45 +01:00
textDecorationLine: account?.moved || account?.suspended ? 'line-through' : undefined
}}
selectable
>
@{localInstance ? instanceAccount?.acct : account?.acct}
{localInstance ? `@${instanceUri}` : null}
</CustomText>
{relationship?.followed_by ? t('shared.account.followed_by') : null}
</CustomText>
2021-01-23 02:41:50 +01:00
{account?.locked ? (
<Icon
name='Lock'
style={{ marginLeft: StyleConstants.Spacing.S }}
2022-02-12 14:51:01 +01:00
color={colors.secondary}
2021-01-23 02:41:50 +01:00
size={StyleConstants.Font.Size.M}
/>
) : null}
{account?.bot ? (
<Icon
name='HardDrive'
style={{ marginLeft: StyleConstants.Spacing.S }}
2022-02-12 14:51:01 +01:00
color={colors.secondary}
2021-01-23 02:41:50 +01:00
size={StyleConstants.Font.Size.M}
/>
) : null}
</View>
)
} else {
return (
<PlaceholderLine
2021-04-24 15:03:17 +02:00
width={StyleConstants.Font.Size.M * 3}
2021-01-23 02:41:50 +01:00
height={StyleConstants.Font.LineHeight.M}
2022-02-12 14:51:01 +01:00
color={colors.shimmerDefault}
2021-01-23 02:41:50 +01:00
noMargin
style={{ borderRadius: 0, marginBottom: StyleConstants.Spacing.L }}
2021-01-23 02:41:50 +01:00
/>
2020-12-27 16:25:29 +01:00
)
}
2021-01-23 02:41:50 +01:00
}
2020-12-27 16:25:29 +01:00
2022-12-12 20:43:45 +01:00
export default AccountInformationAccount