2021-01-03 02:00:26 +01:00
|
|
|
import Icon from '@components/Icon'
|
2021-02-20 19:12:44 +01:00
|
|
|
import {
|
|
|
|
getInstanceAccount,
|
|
|
|
getInstanceUri
|
|
|
|
} from '@utils/slices/instancesSlice'
|
2021-01-03 02:00:26 +01:00
|
|
|
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'
|
2020-12-27 16:25:29 +01:00
|
|
|
import { StyleSheet, Text, 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-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 AccountInformationAccount: React.FC<Props> = ({ account, myInfo }) => {
|
2021-01-23 02:41:50 +01:00
|
|
|
const { theme } = 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 movedStyle = useMemo(
|
|
|
|
() =>
|
|
|
|
StyleSheet.create({
|
|
|
|
base: {
|
|
|
|
textDecorationLine: account?.moved ? 'line-through' : undefined
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
[account?.moved]
|
|
|
|
)
|
|
|
|
const movedContent = useMemo(() => {
|
|
|
|
if (account?.moved) {
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.moved,
|
|
|
|
{ color: theme.secondary, ...StyleConstants.FontStyle.M }
|
|
|
|
]}
|
|
|
|
selectable
|
|
|
|
>
|
|
|
|
@{account.moved.acct}
|
|
|
|
</Text>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}, [account?.moved])
|
2020-12-27 16:25:29 +01:00
|
|
|
|
2021-02-20 19:12:44 +01:00
|
|
|
if (account || (myInfo && instanceAccount)) {
|
2020-12-27 16:25:29 +01:00
|
|
|
return (
|
2021-01-23 02:41:50 +01:00
|
|
|
<View
|
|
|
|
style={[styles.base, { flexDirection: 'row', alignItems: 'center' }]}
|
2020-12-27 16:25:29 +01:00
|
|
|
>
|
2021-01-23 02:41:50 +01:00
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
movedStyle.base,
|
|
|
|
{
|
2020-12-27 16:25:29 +01:00
|
|
|
color: theme.secondary,
|
2020-12-29 00:21:05 +01:00
|
|
|
...StyleConstants.FontStyle.M
|
2021-01-23 02:41:50 +01:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
selectable
|
|
|
|
>
|
2021-02-27 16:33:54 +01:00
|
|
|
@{myInfo ? instanceAccount?.acct : account?.acct}
|
2021-02-20 19:12:44 +01:00
|
|
|
{myInfo ? `@${instanceUri}` : null}
|
2021-01-23 02:41:50 +01:00
|
|
|
</Text>
|
|
|
|
{movedContent}
|
|
|
|
{account?.locked ? (
|
|
|
|
<Icon
|
|
|
|
name='Lock'
|
|
|
|
style={styles.type}
|
|
|
|
color={theme.secondary}
|
|
|
|
size={StyleConstants.Font.Size.M}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{account?.bot ? (
|
|
|
|
<Icon
|
|
|
|
name='HardDrive'
|
|
|
|
style={styles.type}
|
|
|
|
color={theme.secondary}
|
|
|
|
size={StyleConstants.Font.Size.M}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<PlaceholderLine
|
|
|
|
width={StyleConstants.Font.Size.M * 2}
|
|
|
|
height={StyleConstants.Font.LineHeight.M}
|
|
|
|
color={theme.shimmerDefault}
|
|
|
|
noMargin
|
|
|
|
style={styles.base}
|
|
|
|
/>
|
2020-12-27 16:25:29 +01:00
|
|
|
)
|
|
|
|
}
|
2021-01-23 02:41:50 +01:00
|
|
|
}
|
2020-12-27 16:25:29 +01:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2021-01-23 02:41:50 +01:00
|
|
|
base: {
|
|
|
|
borderRadius: 0,
|
|
|
|
marginBottom: StyleConstants.Spacing.L
|
2020-12-27 16:25:29 +01:00
|
|
|
},
|
2021-01-23 02:41:50 +01:00
|
|
|
type: { marginLeft: StyleConstants.Spacing.S },
|
|
|
|
moved: {
|
|
|
|
marginLeft: StyleConstants.Spacing.S
|
|
|
|
}
|
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
|
|
|
|
)
|