From 6e5b06f3a7ab8021698f6d14076a5dbe43e87c38 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Thu, 13 Jul 2023 21:55:26 +0200 Subject: [PATCH] Fix #734 --- src/components/Header/Right.tsx | 4 +- src/components/contextMenu/account.ts | 23 +++-- src/i18n/en/screens/tabs.json | 14 +++ src/screens/Tabs/Shared/Mute.tsx | 130 ++++++++++++++++++++++++++ src/screens/Tabs/Shared/Report.tsx | 1 - src/screens/Tabs/Shared/index.tsx | 7 ++ src/utils/helpers/featureCheck.ts | 2 + src/utils/navigation/navigators.ts | 3 + 8 files changed, 175 insertions(+), 9 deletions(-) create mode 100644 src/screens/Tabs/Shared/Mute.tsx diff --git a/src/components/Header/Right.tsx b/src/components/Header/Right.tsx index a918cbf9..d745a3cd 100644 --- a/src/components/Header/Right.tsx +++ b/src/components/Header/Right.tsx @@ -17,6 +17,7 @@ export type Props = { loading?: boolean disabled?: boolean destructive?: boolean + destructiveColor?: string onPress: () => void } & ({ type?: undefined; content: IconName } | { type: 'text'; content: string }) @@ -34,6 +35,7 @@ const HeaderRight: React.FC = ({ loading, disabled, destructive = false, + destructiveColor, onPress }) => { const { colors } = useTheme() @@ -57,7 +59,7 @@ const HeaderRight: React.FC = ({ color: disabled ? colors.secondary : destructive - ? colors.red + ? destructiveColor || colors.red : colors.primaryDefault, opacity: loading ? 0 : 1 }} diff --git a/src/components/contextMenu/account.ts b/src/components/contextMenu/account.ts index 4da0a947..fd63bb93 100644 --- a/src/components/contextMenu/account.ts +++ b/src/components/contextMenu/account.ts @@ -4,6 +4,7 @@ import { useNavigation } from '@react-navigation/native' import { NativeStackNavigationProp } from '@react-navigation/native-stack' import { useQueryClient } from '@tanstack/react-query' import apiInstance from '@utils/api/instance' +import { featureCheck } from '@utils/helpers/featureCheck' import { checkIsMyAccount } from '@utils/helpers/isMyAccount' import { TabSharedStackParamList, useNavState } from '@utils/navigation/navigators' import { useAccountQuery } from '@utils/queryHooks/account' @@ -203,13 +204,21 @@ const menuAccount = ({ type: 'item', key: 'account-mute', props: { - onSelect: () => - actualAccount && - timelineMutation.mutate({ - type: 'updateAccountProperty', - id: actualAccount.id, - payload: { property: 'mute', currentValue: data?.muting } - }), + onSelect: () => { + if (actualAccount) { + if (data?.muting !== true) { + if (featureCheck('mute_duration')) { + navigation.navigate('Tab-Shared-Mute', { account: actualAccount }) + } + } + + timelineMutation.mutate({ + type: 'updateAccountProperty', + id: actualAccount.id, + payload: { property: 'mute', currentValue: data?.muting } + }) + } + }, disabled: Platform.OS !== 'android' ? !data || !isFetched : false, destructive: false, hidden: false diff --git a/src/i18n/en/screens/tabs.json b/src/i18n/en/screens/tabs.json index f80ea938..979cd57b 100644 --- a/src/i18n/en/screens/tabs.json +++ b/src/i18n/en/screens/tabs.json @@ -417,6 +417,20 @@ "history": { "name": "Edit History" }, + "mute": { + "name": "Mute {{acct}}", + "mute": "Mute", + "description": "Hide posts from this user and posts mentioning them, but it will still allow them to see your posts and follow you.", + "notification": "Also hide notifications from this user", + "duration": { + "heading": "For duration", + "0": "Indefinitely", + "1800": "30 minutes", + "3600": "1 hour", + "86400": "1 day", + "604800": "1 week" + } + }, "report": { "name": "Report {{acct}}", "report": "Report", diff --git a/src/screens/Tabs/Shared/Mute.tsx b/src/screens/Tabs/Shared/Mute.tsx new file mode 100644 index 00000000..f60c28a4 --- /dev/null +++ b/src/screens/Tabs/Shared/Mute.tsx @@ -0,0 +1,130 @@ +import ComponentAccount from '@components/Account' +import { HeaderLeft, HeaderRight } from '@components/Header' +import Icon from '@components/Icon' +import { displayMessage } from '@components/Message' +import { ModalScrollView } from '@components/ModalScrollView' +import Selections from '@components/Selections' +import CustomText from '@components/Text' +import { TabSharedStackScreenProps } from '@utils/navigation/navigators' +import { useTimelineMutation } from '@utils/queryHooks/timeline' +import { StyleConstants } from '@utils/styles/constants' +import { useTheme } from '@utils/styles/ThemeManager' +import React, { useEffect, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { Pressable, View } from 'react-native' + +const TabSharedMute: React.FC> = ({ + navigation, + route: { + params: { account } + } +}) => { + const { colors, theme } = useTheme() + const { t } = useTranslation(['common', 'screenTabs']) + + const { mutateAsync, isLoading } = useTimelineMutation({ + onSuccess: () => + displayMessage({ + type: 'success', + message: t('common:message.success.message', { + function: t('componentContextMenu:account.mute.action', { + defaultValue: 'false', + context: 'false' + }) + }) + }) + }) + + const [durations, setDurations] = useState<{ selected: boolean; content: string }[]>( + (['0', '1800', '3600', '86400', '604800'] as ['0', '1800', '3600', '86400', '604800']).map( + duration => ({ + selected: duration === '0', + content: t(`screenTabs:shared.mute.duration.${duration}`) + }) + ) + ) + const [notification, setNotification] = useState(false) + + useEffect(() => { + navigation.setOptions({ + title: t('screenTabs:shared.mute.name', { acct: `@${account.acct}` }), + headerLeft: () => ( + navigation.goBack()} + /> + ), + headerRight: () => ( + { + await mutateAsync({ + type: 'updateAccountProperty', + id: account.id, + payload: { property: 'mute', currentValue: false } + }) + navigation.pop(1) + }} + loading={isLoading} + /> + ) + }) + }, [theme, isLoading, durations, notification, account.id]) + + return ( + + + + + + + {t('screenTabs:shared.mute.description')} + + + + + setNotification(!notification)} + > + + + {t('screenTabs:shared.mute.notification')} + + + + + ) +} + +export default TabSharedMute diff --git a/src/screens/Tabs/Shared/Report.tsx b/src/screens/Tabs/Shared/Report.tsx index b34ec454..10f399a7 100644 --- a/src/screens/Tabs/Shared/Report.tsx +++ b/src/screens/Tabs/Shared/Report.tsx @@ -21,7 +21,6 @@ const TabSharedReport: React.FC> params: { account, status } } }) => { - console.log('account', account.id) const { colors } = useTheme() const { t } = useTranslation(['common', 'screenTabs']) diff --git a/src/screens/Tabs/Shared/index.tsx b/src/screens/Tabs/Shared/index.tsx index 0b01a052..770ea13d 100644 --- a/src/screens/Tabs/Shared/index.tsx +++ b/src/screens/Tabs/Shared/index.tsx @@ -9,6 +9,7 @@ import TabSharedToot from '@screens/Tabs/Shared/Toot' import TabSharedUsers from '@screens/Tabs/Shared/Users' import React from 'react' import TabSharedFilter from './Filter' +import TabSharedMute from './Mute' const TabShared = ({ Stack }: { Stack: any }) => { return ( @@ -44,6 +45,12 @@ const TabShared = ({ Stack }: { Stack: any }) => { name='Tab-Shared-History' component={TabSharedHistory} /> + + } 'Tab-Shared-Report': { account: Pick status?: Pick