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

115 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-10-30 00:49:05 +01:00
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { Feather } from '@expo/vector-icons'
2020-12-13 14:04:25 +01:00
import Emojis from '@components/Timelines/Timeline/Shared/Emojis'
import { useTheme } from '@utils/styles/ThemeManager'
import { StyleConstants } from '@utils/styles/constants'
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
2020-12-14 23:44:57 +01:00
action: 'favourite' | 'follow' | 'mention' | 'poll' | 'reblog' | 'pinned'
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()
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
2020-10-30 00:49:05 +01:00
let icon
let content
switch (action) {
2020-12-14 23:44:57 +01:00
case 'pinned':
icon = (
<Feather
name='anchor'
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
)
content = `置顶`
break
2020-10-30 00:49:05 +01:00
case 'favourite':
icon = (
2020-11-23 00:07:32 +01:00
<Feather
name='heart'
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.S}
2020-11-23 00:07:32 +01:00
color={iconColor}
style={styles.icon}
/>
2020-10-30 00:49:05 +01:00
)
content = `${name} 喜欢了你的嘟嘟`
break
case 'follow':
icon = (
2020-11-23 00:07:32 +01:00
<Feather
name='user-plus'
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.S}
2020-11-23 00:07:32 +01:00
color={iconColor}
style={styles.icon}
/>
2020-10-30 00:49:05 +01:00
)
content = `${name} 开始关注你`
break
case 'poll':
icon = (
<Feather
name='bar-chart-2'
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.S}
2020-12-30 11:52:47 +01:00
color={iconColor}
2020-10-30 00:49:05 +01:00
style={styles.icon}
/>
)
content = `你参与的投票已结束`
break
case 'reblog':
icon = (
2020-11-23 00:07:32 +01:00
<Feather
name='repeat'
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.S}
2020-11-23 00:07:32 +01:00
color={iconColor}
style={styles.icon}
/>
2020-10-30 00:49:05 +01:00
)
content = `${name} 转嘟了${notification ? '你的嘟嘟' : ''}`
break
}
return (
<View style={styles.actioned}>
{icon}
2020-12-03 01:28:56 +01:00
{content && (
2020-10-30 00:49:05 +01:00
<View style={styles.content}>
2020-12-03 01:28:56 +01:00
{account.emojis ? (
2020-12-30 11:52:47 +01:00
<Emojis content={content} emojis={account.emojis} size='S' />
2020-10-31 21:04:46 +01:00
) : (
<Text>{content}</Text>
)}
2020-10-30 00:49:05 +01:00
</View>
)}
</View>
)
}
const styles = StyleSheet.create({
actioned: {
flexDirection: 'row',
2020-11-30 00:24:53 +01:00
marginBottom: StyleConstants.Spacing.S
2020-10-30 00:49:05 +01:00
},
icon: {
2020-12-19 01:57:57 +01:00
marginLeft: StyleConstants.Avatar.M - StyleConstants.Font.Size.S,
2020-11-30 00:24:53 +01:00
marginRight: StyleConstants.Spacing.S
2020-10-30 00:49:05 +01:00
},
content: {
flexDirection: 'row'
}
})
2020-12-03 01:28:56 +01:00
export default React.memo(TimelineActioned, () => true)