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

104 lines
2.7 KiB
TypeScript
Raw Normal View History

import Icon from '@components/Icon'
import CustomText from '@components/Text'
2021-02-20 19:12:44 +01:00
import {
getInstanceAccount,
getInstanceUri
} from '@utils/slices/instancesSlice'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2021-01-23 02:41:50 +01:00
import React, { useMemo } from 'react'
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
2021-05-09 21:59:03 +02:00
localInstance: boolean
2020-12-27 16:25:29 +01:00
}
2022-02-12 14:51:01 +01:00
const AccountInformationAccount: React.FC<Props> = ({
account,
localInstance
}) => {
const { colors } = useTheme()
2021-02-20 19:12:44 +01:00
const instanceAccount = useSelector(
getInstanceAccount,
2021-02-10 00:40:44 +01:00
(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
2021-01-23 02:41:50 +01:00
const movedContent = useMemo(() => {
if (account?.moved) {
return (
<CustomText
fontStyle='M'
style={{
marginLeft: StyleConstants.Spacing.S,
color: colors.secondary
}}
2021-01-23 02:41:50 +01:00
selectable
>
@{account.moved.acct}
</CustomText>
2021-01-23 02:41:50 +01:00
)
}
}, [account?.moved])
2020-12-27 16:25:29 +01:00
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={{
textDecorationLine: account?.moved ? 'line-through' : undefined,
color: colors.secondary
}}
2021-01-23 02:41:50 +01:00
selectable
>
2021-05-09 21:59:03 +02:00
@{localInstance ? instanceAccount?.acct : account?.acct}
{localInstance ? `@${instanceUri}` : null}
</CustomText>
2021-01-23 02:41:50 +01:00
{movedContent}
{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
2021-01-16 00:00:31 +01:00
export default React.memo(
AccountInformationAccount,
(_, next) => next.account === undefined
)