2021-02-20 19:12:44 +01:00
|
|
|
import { getInstanceAccount } from '@utils/slices/instancesSlice'
|
2020-12-13 14:04:25 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2021-01-23 02:41:50 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
|
|
|
import React, { useCallback } from 'react'
|
|
|
|
import { StyleSheet, View } from 'react-native'
|
2021-01-24 02:25:43 +01:00
|
|
|
import { useSelector } from 'react-redux'
|
2021-01-23 02:41:50 +01:00
|
|
|
import { Placeholder, Fade } from 'rn-placeholder'
|
2020-12-27 16:25:29 +01:00
|
|
|
import AccountInformationAccount from './Information/Account'
|
|
|
|
import AccountInformationActions from './Information/Actions'
|
2021-01-07 19:13:09 +01:00
|
|
|
import AccountInformationAvatar from './Information/Avatar'
|
|
|
|
import AccountInformationCreated from './Information/Created'
|
2020-12-27 16:25:29 +01:00
|
|
|
import AccountInformationFields from './Information/Fields'
|
2021-01-07 19:13:09 +01:00
|
|
|
import AccountInformationName from './Information/Name'
|
2020-12-27 16:25:29 +01:00
|
|
|
import AccountInformationNotes from './Information/Notes'
|
2021-01-07 19:13:09 +01:00
|
|
|
import AccountInformationStats from './Information/Stats'
|
|
|
|
import AccountInformationSwitch from './Information/Switch'
|
2020-11-22 00:46:23 +01:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
account: Mastodon.Account | undefined
|
2021-01-24 02:25:43 +01:00
|
|
|
myInfo?: boolean // Showing from my info page
|
2020-11-22 00:46:23 +01:00
|
|
|
}
|
|
|
|
|
2021-01-24 02:25:43 +01:00
|
|
|
const AccountInformation: React.FC<Props> = ({ account, myInfo = false }) => {
|
2021-02-10 00:40:44 +01:00
|
|
|
const ownAccount =
|
|
|
|
account?.id ===
|
2021-02-20 19:12:44 +01:00
|
|
|
useSelector(getInstanceAccount, (prev, next) => prev?.id === next?.id)?.id
|
2021-01-23 02:41:50 +01:00
|
|
|
const { mode, theme } = useTheme()
|
|
|
|
|
|
|
|
const animation = useCallback(
|
|
|
|
props => (
|
|
|
|
<Fade {...props} style={{ backgroundColor: theme.shimmerHighlight }} />
|
|
|
|
),
|
|
|
|
[mode]
|
|
|
|
)
|
2020-12-14 23:44:57 +01:00
|
|
|
|
2020-11-22 00:46:23 +01:00
|
|
|
return (
|
2021-01-16 00:00:31 +01:00
|
|
|
<View style={styles.base}>
|
2021-01-23 02:41:50 +01:00
|
|
|
<Placeholder Animation={animation}>
|
|
|
|
<View style={styles.avatarAndActions}>
|
2021-01-24 02:25:43 +01:00
|
|
|
<AccountInformationAvatar account={account} myInfo={myInfo} />
|
2021-01-23 02:41:50 +01:00
|
|
|
<View style={styles.actions}>
|
2021-01-24 02:25:43 +01:00
|
|
|
{myInfo ? (
|
2021-01-23 02:41:50 +01:00
|
|
|
<AccountInformationSwitch />
|
|
|
|
) : (
|
2021-01-24 02:25:43 +01:00
|
|
|
<AccountInformationActions
|
|
|
|
account={account}
|
|
|
|
ownAccount={ownAccount}
|
|
|
|
/>
|
2021-01-23 02:41:50 +01:00
|
|
|
)}
|
|
|
|
</View>
|
2021-01-07 19:13:09 +01:00
|
|
|
</View>
|
2020-11-22 00:46:23 +01:00
|
|
|
|
2021-01-23 02:41:50 +01:00
|
|
|
<AccountInformationName account={account} />
|
2020-12-14 23:44:57 +01:00
|
|
|
|
2021-01-24 02:25:43 +01:00
|
|
|
<AccountInformationAccount account={account} myInfo={myInfo} />
|
2020-11-22 00:46:23 +01:00
|
|
|
|
2021-01-24 02:25:43 +01:00
|
|
|
{!myInfo ? (
|
2021-01-23 02:41:50 +01:00
|
|
|
<>
|
|
|
|
{account?.fields && account.fields.length > 0 ? (
|
|
|
|
<AccountInformationFields account={account} />
|
|
|
|
) : null}
|
|
|
|
{account?.note &&
|
|
|
|
account.note.length > 0 &&
|
|
|
|
account.note !== '<p></p>' ? (
|
|
|
|
// Empty notes might generate empty p tag
|
|
|
|
<AccountInformationNotes account={account} />
|
|
|
|
) : null}
|
|
|
|
<AccountInformationCreated account={account} />
|
|
|
|
</>
|
|
|
|
) : null}
|
2020-11-23 00:07:32 +01:00
|
|
|
|
2021-01-24 02:25:43 +01:00
|
|
|
<AccountInformationStats account={account} myInfo={myInfo} />
|
2021-01-23 02:41:50 +01:00
|
|
|
</Placeholder>
|
2020-11-22 00:46:23 +01:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2020-12-21 21:47:15 +01:00
|
|
|
base: {
|
2021-02-01 02:16:53 +01:00
|
|
|
marginTop: -StyleConstants.Avatar.L / 2,
|
2021-01-16 00:00:31 +01:00
|
|
|
padding: StyleConstants.Spacing.Global.PagePadding
|
2020-11-23 00:07:32 +01:00
|
|
|
},
|
2020-12-21 21:47:15 +01:00
|
|
|
avatarAndActions: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'space-between'
|
2021-01-07 19:13:09 +01:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
flexDirection: 'row'
|
2020-11-22 00:46:23 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-02-02 22:50:38 +01:00
|
|
|
export default React.memo(AccountInformation, (prev, next) => {
|
|
|
|
let skipUpdate = true
|
|
|
|
skipUpdate = prev.account?.id === next.account?.id
|
|
|
|
skipUpdate = prev.account?.acct === next.account?.acct
|
|
|
|
return skipUpdate
|
|
|
|
})
|