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

84 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-05-09 21:59:03 +02:00
import Input from '@components/Input'
2021-01-01 16:48:16 +01:00
import { ParseEmojis } from '@components/Parse'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2021-05-09 21:59:03 +02:00
import React, { useMemo, useState } from 'react'
2021-01-23 02:41:50 +01:00
import { StyleSheet, Text, View } from 'react-native'
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
edit?: boolean // Editing mode
2020-12-27 16:25:29 +01:00
}
2021-05-09 21:59:03 +02:00
const AccountInformationName: React.FC<Props> = ({ account, edit }) => {
2021-01-23 02:41:50 +01:00
const { theme } = useTheme()
2020-12-27 16:25:29 +01:00
2021-01-23 02:41:50 +01:00
const movedContent = useMemo(() => {
if (account?.moved) {
return (
<View style={styles.moved}>
<ParseEmojis
content={account.moved.display_name || account.moved.username}
emojis={account.moved.emojis}
size='L'
fontBold
/>
</View>
)
}
}, [account?.moved])
2021-05-09 21:59:03 +02:00
const [displatName, setDisplayName] = useState(account?.display_name)
2021-04-24 15:03:17 +02:00
return (
<View style={[styles.base, { flexDirection: 'row' }]}>
{account ? (
2021-05-09 21:59:03 +02:00
edit ? (
<Input title='昵称' value={displatName} setValue={setDisplayName} />
) : (
<>
<Text
style={{
textDecorationLine: account?.moved ? 'line-through' : undefined
}}
>
<ParseEmojis
content={account.display_name || account.username}
emojis={account.emojis}
size='L'
fontBold
/>
</Text>
{movedContent}
</>
)
2021-04-24 15:03:17 +02:00
) : (
<PlaceholderLine
width={StyleConstants.Font.Size.L * 2}
height={StyleConstants.Font.LineHeight.L}
color={theme.shimmerDefault}
noMargin
style={{ borderRadius: 0 }}
/>
)}
</View>
)
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,
2021-01-31 03:09:35 +01:00
marginTop: StyleConstants.Spacing.S,
2020-12-27 16:25:29 +01:00
marginBottom: StyleConstants.Spacing.XS
2021-01-23 02:41:50 +01:00
},
moved: {
marginLeft: StyleConstants.Spacing.S
2020-12-27 16:25:29 +01:00
}
})
2021-01-23 02:41:50 +01:00
export default React.memo(
AccountInformationName,
(_, next) => next.account === undefined
)