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

208 lines
5.9 KiB
TypeScript
Raw Normal View History

import Icon from '@components/Icon'
2021-01-01 23:10:47 +01:00
import { ParseEmojis } from '@components/Parse'
import { useNavigation } from '@react-navigation/native'
2021-01-24 02:25:43 +01:00
import { StackNavigationProp } from '@react-navigation/stack'
2022-04-29 23:57:18 +02:00
import { TabLocalStackParamList } from '@utils/navigation/navigators'
2023-02-03 13:57:11 +01:00
import { getAccountStorage } from '@utils/storage/actions'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
2021-01-01 23:10:47 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2022-12-03 20:47:11 +01:00
import React, { useContext } from 'react'
2021-01-01 23:10:47 +01:00
import { useTranslation } from 'react-i18next'
2021-01-01 16:48:16 +01:00
import { Pressable, StyleSheet, View } from 'react-native'
2022-12-03 20:47:11 +01:00
import StatusContext from './Context'
2020-10-30 00:49:05 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
2022-12-03 20:47:11 +01:00
action: Mastodon.Notification['type'] | 'reblog' | 'pinned'
isNotification?: boolean
2022-12-05 14:50:03 +01:00
account?: Mastodon.Account // For notification
2023-01-01 18:37:05 +01:00
rootStatus?: Mastodon.Status
2020-10-31 21:04:46 +01:00
}
2022-12-03 20:47:11 +01:00
const TimelineActioned: React.FC<Props> = ({ action, isNotification, ...rest }) => {
2023-01-01 18:37:05 +01:00
const { status } = useContext(StatusContext)
const account = rest.account || (rest.rootStatus || status)?.account
if (!account) return null
2020-11-23 00:07:32 +01:00
2022-12-03 20:47:11 +01:00
const { t } = useTranslation('componentTimeline')
const { colors } = useTheme()
const navigation = useNavigation<StackNavigationProp<TabLocalStackParamList>>()
const name = account?.display_name || account?.username
const iconColor = colors.primaryDefault
2021-01-01 16:48:16 +01:00
2022-12-03 20:47:11 +01:00
const content = (content: string) => (
2022-12-12 23:57:07 +01:00
<ParseEmojis
content={content}
emojis={account.emojis}
size='S'
style={{ color: action === 'admin.report' ? colors.red : colors.primaryDefault }}
/>
2022-12-03 20:47:11 +01:00
)
2021-01-01 16:48:16 +01:00
2023-02-03 13:57:11 +01:00
const onPress = () => navigation.push('Tab-Shared-Account', { account })
2022-12-03 20:47:11 +01:00
const children = () => {
switch (action) {
case 'pinned':
return (
<>
<Icon
name='anchor'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
{content(t('shared.actioned.pinned'))}
</>
)
case 'favourite':
return (
<>
<Icon
name='heart'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(t('shared.actioned.favourite', { name }))}
</Pressable>
</>
)
case 'follow':
return (
<>
<Icon
name='user-plus'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(t('shared.actioned.follow', { name }))}
</Pressable>
</>
)
case 'follow_request':
return (
<>
<Icon
name='user-plus'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(t('shared.actioned.follow_request', { name }))}
</Pressable>
</>
)
case 'poll':
return (
<>
<Icon
name='bar-chart-2'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
{content(t('shared.actioned.poll'))}
</>
)
case 'reblog':
2023-02-03 13:57:11 +01:00
const myself = rest.rootStatus?.account.id === getAccountStorage.string('auth.account.id')
2022-12-03 20:47:11 +01:00
return (
<>
<Icon
name='repeat'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(
isNotification
? t('shared.actioned.reblog.notification', { name })
2023-02-03 13:57:11 +01:00
: myself
? t('shared.actioned.reblog.myself')
2022-12-03 20:47:11 +01:00
: t('shared.actioned.reblog.default', { name })
)}
</Pressable>
</>
)
case 'status':
return (
<>
<Icon
name='activity'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
<Pressable onPress={onPress}>
{content(t('shared.actioned.status', { name }))}
</Pressable>
</>
)
case 'update':
return (
<>
<Icon
name='bar-chart-2'
2022-12-03 20:47:11 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
{content(t('shared.actioned.update'))}
</>
)
2022-12-12 23:57:07 +01:00
case 'admin.sign_up':
return (
<>
<Icon
name='users'
2022-12-12 23:57:07 +01:00
size={StyleConstants.Font.Size.S}
color={iconColor}
style={styles.icon}
/>
{content(t('shared.actioned.admin.sign_up', { name: `@${account.acct}` }))}
</>
)
case 'admin.report':
return (
<>
<Icon
name='alert-octagon'
2022-12-12 23:57:07 +01:00
size={StyleConstants.Font.Size.S}
color={colors.red}
style={styles.icon}
/>
{content(t('shared.actioned.admin.report', { name: `@${account.acct}` }))}
</>
)
2022-12-03 20:47:11 +01:00
default:
return <></>
}
2022-12-03 20:47:11 +01:00
}
2021-01-01 16:48:16 +01:00
2022-12-03 20:47:11 +01:00
return (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginBottom: StyleConstants.Spacing.S,
paddingLeft: StyleConstants.Avatar.M - StyleConstants.Font.Size.S,
paddingRight: StyleConstants.Spacing.Global.PagePadding
}}
children={children()}
/>
)
}
2020-10-30 00:49:05 +01:00
const styles = StyleSheet.create({
icon: {
marginRight: StyleConstants.Spacing.S
2020-10-30 00:49:05 +01:00
}
})
2021-02-27 16:33:54 +01:00
export default TimelineActioned