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

109 lines
2.4 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'
import Emojis from './Emojis'
2020-11-23 00:07:32 +01:00
import { useTheme } from 'src/utils/styles/ThemeManager'
2020-11-30 00:24:53 +01:00
import { StyleConstants } from 'src/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-10-31 21:04:46 +01:00
action: 'favourite' | 'follow' | 'mention' | 'poll' | 'reblog'
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) {
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-10-30 00:49:05 +01:00
color='black'
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-11-23 00:07:32 +01:00
<Emojis
content={content}
2020-12-03 01:28:56 +01:00
emojis={account.emojis}
2020-11-30 00:24:53 +01:00
size={StyleConstants.Font.Size.S}
2020-11-23 00:07:32 +01:00
/>
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-11-30 00:24:53 +01:00
marginLeft: StyleConstants.Avatar.S - StyleConstants.Font.Size.S,
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)