2022-06-06 22:49:43 +02:00
|
|
|
import { displayMessage } from '@components/Message'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { useQueryClient } from '@tanstack/react-query'
|
2022-11-22 21:39:25 +01:00
|
|
|
import { QueryKeyTimeline, useTimelineMutation } from '@utils/queryHooks/timeline'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { getAccountStorage } from '@utils/storage/actions'
|
2023-03-13 23:16:41 +01:00
|
|
|
import * as Linking from 'expo-linking'
|
2022-06-06 22:49:43 +02:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2022-12-03 01:08:38 +01:00
|
|
|
import { Alert } from 'react-native'
|
2022-06-06 22:49:43 +02:00
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
const menuInstance = ({
|
|
|
|
status,
|
2023-01-04 22:39:29 +01:00
|
|
|
queryKey
|
2022-12-03 01:08:38 +01:00
|
|
|
}: {
|
|
|
|
status?: Mastodon.Status
|
|
|
|
queryKey?: QueryKeyTimeline
|
2023-01-08 16:59:35 +01:00
|
|
|
}): ContextMenu => {
|
2022-12-03 01:08:38 +01:00
|
|
|
if (!status || !queryKey) return []
|
2022-06-06 22:49:43 +02:00
|
|
|
|
2022-12-23 15:53:40 +01:00
|
|
|
const { t } = useTranslation(['common', 'componentContextMenu'])
|
2022-06-06 22:49:43 +02:00
|
|
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
const mutation = useTimelineMutation({
|
|
|
|
onSettled: () => {
|
|
|
|
displayMessage({
|
|
|
|
type: 'success',
|
|
|
|
message: t('common:message.success.message', {
|
2022-12-23 15:53:40 +01:00
|
|
|
function: t(`componentContextMenu:instance.block.action`, { instance })
|
2022-06-06 22:49:43 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
queryClient.invalidateQueries(queryKey)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-01-08 16:59:35 +01:00
|
|
|
const menus: ContextMenu = []
|
2022-12-03 01:08:38 +01:00
|
|
|
|
2023-03-13 23:16:41 +01:00
|
|
|
const instance = Linking.parse(status.uri).hostname
|
2022-12-03 01:08:38 +01:00
|
|
|
|
2023-03-13 23:16:41 +01:00
|
|
|
if (instance && instance !== getAccountStorage.string('auth.domain')) {
|
2022-12-03 01:08:38 +01:00
|
|
|
menus.push([
|
|
|
|
{
|
2023-01-08 16:59:35 +01:00
|
|
|
type: 'item',
|
2022-12-03 01:08:38 +01:00
|
|
|
key: 'instance-block',
|
2023-01-08 16:59:35 +01:00
|
|
|
props: {
|
2022-12-03 01:08:38 +01:00
|
|
|
onSelect: () =>
|
|
|
|
Alert.alert(
|
2022-12-23 15:53:40 +01:00
|
|
|
t('componentContextMenu:instance.block.alert.title', { instance }),
|
|
|
|
t('componentContextMenu:instance.block.alert.message'),
|
2022-12-03 01:08:38 +01:00
|
|
|
[
|
|
|
|
{
|
2022-12-19 23:06:39 +01:00
|
|
|
text: t('common:buttons.confirm'),
|
2022-12-03 01:08:38 +01:00
|
|
|
style: 'destructive',
|
|
|
|
onPress: () => {
|
2023-01-04 22:39:29 +01:00
|
|
|
mutation.mutate({ type: 'domainBlock', domain: instance })
|
2022-12-03 01:08:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: t('common:buttons.cancel')
|
|
|
|
}
|
|
|
|
]
|
|
|
|
),
|
|
|
|
disabled: false,
|
|
|
|
destructive: true,
|
|
|
|
hidden: false
|
|
|
|
},
|
2022-12-23 15:53:40 +01:00
|
|
|
title: t('componentContextMenu:instance.block.action', { instance }),
|
2022-12-03 01:08:38 +01:00
|
|
|
icon: ''
|
|
|
|
}
|
|
|
|
])
|
2022-06-06 22:49:43 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
return menus
|
2022-06-06 22:49:43 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
export default menuInstance
|