2021-01-30 01:29:15 +01:00
|
|
|
import analytics from '@components/analytics'
|
|
|
|
import { MenuContainer, MenuHeader, MenuRow } from '@components/Menu'
|
2021-02-28 22:49:55 +01:00
|
|
|
import { displayMessage } from '@components/Message'
|
2021-01-30 01:29:15 +01:00
|
|
|
import {
|
|
|
|
MutationVarsTimelineUpdateAccountProperty,
|
|
|
|
QueryKeyTimeline,
|
|
|
|
useTimelineMutation
|
|
|
|
} from '@utils/queryHooks/timeline'
|
2021-02-28 22:49:55 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2021-01-30 01:29:15 +01:00
|
|
|
import React from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useQueryClient } from 'react-query'
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
queryKey?: QueryKeyTimeline
|
2021-02-13 01:26:02 +01:00
|
|
|
rootQueryKey?: QueryKeyTimeline
|
2021-01-30 01:29:15 +01:00
|
|
|
account: Mastodon.Account
|
|
|
|
dismiss: () => void
|
|
|
|
}
|
|
|
|
|
2021-02-13 01:26:02 +01:00
|
|
|
const ActionsAccount: React.FC<Props> = ({
|
|
|
|
queryKey,
|
|
|
|
rootQueryKey,
|
|
|
|
account,
|
|
|
|
dismiss
|
|
|
|
}) => {
|
2021-02-28 22:49:55 +01:00
|
|
|
const { mode } = useTheme()
|
2021-01-30 01:29:15 +01:00
|
|
|
const { t } = useTranslation('componentTimeline')
|
|
|
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
const mutateion = useTimelineMutation({
|
|
|
|
onSuccess: (_, params) => {
|
|
|
|
const theParams = params as MutationVarsTimelineUpdateAccountProperty
|
2021-02-28 22:49:55 +01:00
|
|
|
displayMessage({
|
|
|
|
mode,
|
2021-01-30 01:29:15 +01:00
|
|
|
type: 'success',
|
2021-03-28 23:31:10 +02:00
|
|
|
message: t('common:message.success.message', {
|
2021-01-30 01:29:15 +01:00
|
|
|
function: t(
|
|
|
|
`shared.header.actions.account.${theParams.payload.property}.function`,
|
|
|
|
{
|
|
|
|
acct: account.acct
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onError: (err: any, params) => {
|
|
|
|
const theParams = params as MutationVarsTimelineUpdateAccountProperty
|
2021-02-28 22:49:55 +01:00
|
|
|
displayMessage({
|
|
|
|
mode,
|
2021-01-30 01:29:15 +01:00
|
|
|
type: 'error',
|
2021-03-28 23:31:10 +02:00
|
|
|
message: t('common:message.error.message', {
|
2021-01-30 01:29:15 +01:00
|
|
|
function: t(
|
|
|
|
`shared.header.actions.account.${theParams.payload.property}.function`
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
...(err.status &&
|
|
|
|
typeof err.status === 'number' &&
|
|
|
|
err.data &&
|
|
|
|
err.data.error &&
|
|
|
|
typeof err.data.error === 'string' && {
|
|
|
|
description: err.data.error
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onSettled: () => {
|
|
|
|
queryKey && queryClient.invalidateQueries(queryKey)
|
2021-02-13 01:26:02 +01:00
|
|
|
rootQueryKey && queryClient.invalidateQueries(rootQueryKey)
|
2021-01-30 01:29:15 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<MenuContainer>
|
|
|
|
<MenuHeader heading={t('shared.header.actions.account.heading')} />
|
|
|
|
<MenuRow
|
|
|
|
onPress={() => {
|
|
|
|
analytics('timeline_shared_headeractions_account_mute_press', {
|
|
|
|
page: queryKey && queryKey[1].page
|
|
|
|
})
|
|
|
|
dismiss()
|
|
|
|
mutateion.mutate({
|
|
|
|
type: 'updateAccountProperty',
|
|
|
|
queryKey,
|
|
|
|
id: account.id,
|
|
|
|
payload: { property: 'mute' }
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
iconFront='EyeOff'
|
|
|
|
title={t('shared.header.actions.account.mute.button', {
|
|
|
|
acct: account.acct
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<MenuRow
|
|
|
|
onPress={() => {
|
|
|
|
analytics('timeline_shared_headeractions_account_block_press', {
|
|
|
|
page: queryKey && queryKey[1].page
|
|
|
|
})
|
|
|
|
dismiss()
|
|
|
|
mutateion.mutate({
|
|
|
|
type: 'updateAccountProperty',
|
|
|
|
queryKey,
|
|
|
|
id: account.id,
|
|
|
|
payload: { property: 'block' }
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
iconFront='XCircle'
|
|
|
|
title={t('shared.header.actions.account.block.button', {
|
|
|
|
acct: account.acct
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<MenuRow
|
|
|
|
onPress={() => {
|
|
|
|
analytics('timeline_shared_headeractions_account_reports_press', {
|
|
|
|
page: queryKey && queryKey[1].page
|
|
|
|
})
|
|
|
|
dismiss()
|
|
|
|
mutateion.mutate({
|
|
|
|
type: 'updateAccountProperty',
|
|
|
|
queryKey,
|
|
|
|
id: account.id,
|
|
|
|
payload: { property: 'reports' }
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
iconFront='Flag'
|
|
|
|
title={t('shared.header.actions.account.reports.button', {
|
|
|
|
acct: account.acct
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</MenuContainer>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ActionsAccount
|