tooot/src/components/Timelines/Timeline/Shared/Actioned.tsx

125 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-10-30 00:49:05 +01:00
import { Feather } from '@expo/vector-icons'
2020-12-13 14:04:25 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
import { StyleConstants } from '@utils/styles/constants'
2021-01-01 16:48:16 +01:00
import React, { useCallback, useMemo } from 'react'
import { Pressable, StyleSheet, View } from 'react-native'
import { ParseEmojis } from '@root/components/Parse'
import { useNavigation } from '@react-navigation/native'
2020-10-30 00:49:05 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
2020-12-03 01:28:56 +01:00
account: Mastodon.Account
2021-01-01 16:48:16 +01:00
action: 'favourite' | 'follow' | 'poll' | 'reblog' | 'pinned' | 'mention'
2020-10-31 21:04:46 +01:00
notification?: boolean
}
2020-12-03 01:28:56 +01:00
const TimelineActioned: React.FC<Props> = ({
account,
2020-10-30 00:49:05 +01:00
action,
notification = false
2020-10-31 21:04:46 +01:00
}) => {
2020-11-23 00:07:32 +01:00
const { theme } = useTheme()
2021-01-01 16:48:16 +01:00
const navigation = useNavigation()
2020-12-03 01:28:56 +01:00
const name = account.display_name || account.username
2020-11-23 00:07:32 +01:00
const iconColor = theme.primary
2021-01-01 16:48:16 +01:00
const content = (content: string) => (
<ParseEmojis content={content} emojis={account.emojis} size='S' />
2020-10-30 00:49:05 +01:00
)
2021-01-01 16:48:16 +01:00
const onPress = useCallback(() => {
navigation.push('Screen-Shared-Account', { account })
}, [])
const children = useMemo(() => {
switch (action) {
case 'pinned':
return (
<>
<Feather
name='anchor'
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
{content('置顶')}
</>
)
break
case 'favourite':
return (
<>
<Feather
name='heart'
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(`${name} 喜欢了你的嘟嘟`)}
</Pressable>
</>
)
break
case 'follow':
return (
<>
<Feather
name='user-plus'
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(`${name} 开始关注你`)}
</Pressable>
</>
)
break
case 'poll':
return (
<>
<Feather
name='bar-chart-2'
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
{content('你参与的投票已结束')}
</>
)
break
case 'reblog':
return (
<>
<Feather
name='repeat'
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(`${name} 转嘟了${notification ? '你的嘟嘟' : ''}`)}
</Pressable>
</>
)
break
}
}, [])
return <View style={styles.actioned} children={children} />
2020-10-30 00:49:05 +01:00
}
const styles = StyleSheet.create({
actioned: {
flexDirection: 'row',
2021-01-01 16:48:16 +01:00
marginBottom: StyleConstants.Spacing.S,
paddingLeft: StyleConstants.Avatar.M - StyleConstants.Font.Size.S,
paddingRight: StyleConstants.Spacing.Global.PagePadding
2020-10-30 00:49:05 +01:00
},
icon: {
2021-01-01 16:48:16 +01:00
paddingRight: StyleConstants.Spacing.S
2020-10-30 00:49:05 +01:00
}
})
2020-12-03 01:28:56 +01:00
export default React.memo(TimelineActioned, () => true)