2021-01-24 02:25:43 +01:00
|
|
|
import analytics from '@components/analytics'
|
2021-01-04 10:50:24 +01:00
|
|
|
import Button from '@components/Button'
|
|
|
|
import haptics from '@components/haptics'
|
2021-02-28 22:49:55 +01:00
|
|
|
import { displayMessage } from '@components/Message'
|
2021-01-11 21:36:57 +01:00
|
|
|
import {
|
|
|
|
QueryKeyRelationship,
|
|
|
|
useRelationshipMutation
|
|
|
|
} from '@utils/queryHooks/relationship'
|
|
|
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
2021-01-04 10:50:24 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2021-02-28 22:49:55 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2021-01-11 21:36:57 +01:00
|
|
|
import React from 'react'
|
2021-01-04 10:50:24 +01:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { StyleSheet, View } from 'react-native'
|
2021-01-11 21:36:57 +01:00
|
|
|
import { useQueryClient } from 'react-query'
|
2021-01-04 10:50:24 +01:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
id: Mastodon.Account['id']
|
|
|
|
}
|
|
|
|
|
|
|
|
const RelationshipIncoming: React.FC<Props> = ({ id }) => {
|
2022-02-12 14:51:01 +01:00
|
|
|
const { theme } = useTheme()
|
2021-01-04 10:50:24 +01:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2021-01-10 02:12:14 +01:00
|
|
|
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }]
|
2021-01-11 21:36:57 +01:00
|
|
|
const queryKeyNotification: QueryKeyTimeline = [
|
|
|
|
'Timeline',
|
|
|
|
{ page: 'Notifications' }
|
|
|
|
]
|
2021-01-04 10:50:24 +01:00
|
|
|
const queryClient = useQueryClient()
|
2021-01-11 21:36:57 +01:00
|
|
|
const mutation = useRelationshipMutation({
|
2021-01-07 19:13:09 +01:00
|
|
|
onSuccess: res => {
|
2021-01-04 10:50:24 +01:00
|
|
|
haptics('Success')
|
2021-01-11 21:36:57 +01:00
|
|
|
queryClient.setQueryData<Mastodon.Relationship[]>(queryKeyRelationship, [
|
|
|
|
res
|
|
|
|
])
|
|
|
|
queryClient.refetchQueries(queryKeyNotification)
|
2021-01-04 10:50:24 +01:00
|
|
|
},
|
|
|
|
onError: (err: any, { type }) => {
|
|
|
|
haptics('Error')
|
2021-02-28 22:49:55 +01:00
|
|
|
displayMessage({
|
2021-01-04 10:50:24 +01:00
|
|
|
type: 'error',
|
2022-02-12 14:51:01 +01:00
|
|
|
theme,
|
2021-03-28 23:31:10 +02:00
|
|
|
message: t('common:message.error.message', {
|
2021-01-04 10:50:24 +01:00
|
|
|
function: t(`relationship:${type}.function`)
|
|
|
|
}),
|
|
|
|
...(err.status &&
|
|
|
|
typeof err.status === 'number' &&
|
|
|
|
err.data &&
|
|
|
|
err.data.error &&
|
|
|
|
typeof err.data.error === 'string' && {
|
|
|
|
description: err.data.error
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.base}>
|
|
|
|
<Button
|
|
|
|
round
|
|
|
|
type='icon'
|
|
|
|
content='X'
|
|
|
|
loading={mutation.isLoading}
|
2021-01-24 02:25:43 +01:00
|
|
|
onPress={() => {
|
|
|
|
analytics('relationship_incoming_press_reject')
|
2021-01-11 21:36:57 +01:00
|
|
|
mutation.mutate({
|
|
|
|
id,
|
|
|
|
type: 'incoming',
|
|
|
|
payload: { action: 'reject' }
|
|
|
|
})
|
2021-01-24 02:25:43 +01:00
|
|
|
}}
|
2021-01-04 10:50:24 +01:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
round
|
|
|
|
type='icon'
|
|
|
|
content='Check'
|
|
|
|
loading={mutation.isLoading}
|
2021-01-24 02:25:43 +01:00
|
|
|
onPress={() => {
|
|
|
|
analytics('relationship_incoming_press_authorize')
|
2021-01-11 21:36:57 +01:00
|
|
|
mutation.mutate({
|
|
|
|
id,
|
|
|
|
type: 'incoming',
|
|
|
|
payload: { action: 'authorize' }
|
|
|
|
})
|
2021-01-24 02:25:43 +01:00
|
|
|
}}
|
2021-01-04 10:50:24 +01:00
|
|
|
style={styles.approve}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
base: {
|
|
|
|
flexShrink: 1,
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
approve: {
|
|
|
|
marginLeft: StyleConstants.Spacing.M
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default RelationshipIncoming
|