tooot/src/screens/Shared/Account/Information/Actions.tsx

77 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
import Button from '@components/Button'
import { RelationshipOutgoing } from '@components/Relationship'
2020-12-27 16:25:29 +01:00
import { useNavigation } from '@react-navigation/native'
2021-01-24 02:25:43 +01:00
import { StackNavigationProp } from '@react-navigation/stack'
2021-01-11 21:36:57 +01:00
import { useRelationshipQuery } from '@utils/queryHooks/relationship'
import { StyleConstants } from '@utils/styles/constants'
import React from 'react'
2021-01-23 02:41:50 +01:00
import { useTranslation } from 'react-i18next'
2021-01-07 19:13:09 +01:00
import { StyleSheet } from 'react-native'
2020-12-27 16:25:29 +01:00
export interface Props {
account: Mastodon.Account | undefined
2021-01-24 02:25:43 +01:00
ownAccount: boolean
2020-12-27 16:25:29 +01:00
}
2021-01-24 02:25:43 +01:00
const GoToMoved = ({ accountMoved }: { accountMoved: Mastodon.Account }) => {
2021-01-23 02:41:50 +01:00
const { t } = useTranslation('sharedAccount')
2021-01-24 02:25:43 +01:00
const navigation = useNavigation<
StackNavigationProp<Nav.LocalStackParamList>
>()
2021-01-23 02:41:50 +01:00
2021-01-24 02:25:43 +01:00
return (
2021-01-23 02:41:50 +01:00
<Button
type='text'
content={t('content.moved')}
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('account_gotomoved_press')
navigation.push('Screen-Shared-Account', { account: accountMoved })
}}
2021-01-23 02:41:50 +01:00
/>
2021-01-24 02:25:43 +01:00
)
2021-01-23 02:41:50 +01:00
}
2021-01-07 19:13:09 +01:00
const Conversation = ({ account }: { account: Mastodon.Account }) => {
2020-12-27 16:25:29 +01:00
const navigation = useNavigation()
2021-01-11 21:36:57 +01:00
const query = useRelationshipQuery({ id: account.id })
2021-01-07 19:13:09 +01:00
return query.data && !query.data.blocked_by ? (
<Button
round
type='icon'
content='Mail'
style={styles.actionConversation}
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('account_DM_press')
2021-01-07 19:13:09 +01:00
navigation.navigate('Screen-Shared-Compose', {
type: 'conversation',
2021-01-24 02:25:43 +01:00
accts: [account.acct]
2021-01-07 19:13:09 +01:00
})
2021-01-24 02:25:43 +01:00
}}
2021-01-07 19:13:09 +01:00
/>
) : null
}
2020-12-27 16:25:29 +01:00
2021-01-24 02:25:43 +01:00
const AccountInformationActions: React.FC<Props> = ({
account,
ownAccount
}) => {
2021-01-07 19:13:09 +01:00
return account && account.id ? (
2021-01-23 02:41:50 +01:00
account.moved ? (
2021-01-24 02:25:43 +01:00
<GoToMoved accountMoved={account.moved} />
) : !ownAccount ? (
2021-01-23 02:41:50 +01:00
<>
<Conversation account={account} />
<RelationshipOutgoing id={account.id} />
</>
2021-01-24 02:25:43 +01:00
) : null
2021-01-07 19:13:09 +01:00
) : null
2020-12-27 16:25:29 +01:00
}
const styles = StyleSheet.create({
actionConversation: { marginRight: StyleConstants.Spacing.S }
2020-12-27 16:25:29 +01:00
})
export default AccountInformationActions