tooot/src/screens/Actions/Account.tsx

124 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-01-30 01:29:15 +01:00
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
}) => {
2022-02-12 14:51:01 +01:00
const { theme } = useTheme()
2021-01-30 01:29:15 +01:00
const { t } = useTranslation('componentTimeline')
const queryClient = useQueryClient()
const mutation = useTimelineMutation({
2021-01-30 01:29:15 +01:00
onSuccess: (_, params) => {
const theParams = params as MutationVarsTimelineUpdateAccountProperty
2021-02-28 22:49:55 +01:00
displayMessage({
2022-02-12 14:51:01 +01:00
theme,
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({
2022-02-12 14:51:01 +01:00
theme,
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={() => {
dismiss()
mutation.mutate({
2021-01-30 01:29:15 +01:00
type: 'updateAccountProperty',
queryKey,
id: account.id,
payload: { property: 'mute' }
})
}}
iconFront='EyeOff'
title={t('shared.header.actions.account.mute.button', {
acct: account.acct
})}
/>
<MenuRow
onPress={() => {
dismiss()
mutation.mutate({
2021-01-30 01:29:15 +01:00
type: 'updateAccountProperty',
queryKey,
id: account.id,
payload: { property: 'block' }
})
}}
iconFront='XCircle'
title={t('shared.header.actions.account.block.button', {
acct: account.acct
})}
/>
<MenuRow
onPress={() => {
dismiss()
mutation.mutate({
2021-01-30 01:29:15 +01:00
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