import ComponentAccount from '@components/Account' import { HeaderLeft, HeaderRight } from '@components/Header' import { ModalScrollView } from '@components/ModalScrollView' import Selections from '@components/Selections' import CustomText from '@components/Text' import apiInstance from '@utils/api/instance' import { TabSharedStackScreenProps } from '@utils/navigation/navigators' import { useRulesQuery } from '@utils/queryHooks/reports' import { searchLocalStatus } from '@utils/queryHooks/search' import { getAccountStorage } from '@utils/storage/actions' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { Platform, TextInput, View } from 'react-native' import { Switch } from 'react-native-gesture-handler' const TabSharedReport: React.FC> = ({ navigation, route: { params: { account, status } } }) => { console.log('account', account.id) const { colors } = useTheme() const { t } = useTranslation(['common', 'screenTabs']) const [categories, setCategories] = useState< { selected: boolean; content: string; type: 'spam' | 'other' | 'violation' }[] >([ { selected: true, content: t('screenTabs:shared.report.reasons.spam'), type: 'spam' }, { selected: false, content: t('screenTabs:shared.report.reasons.other'), type: 'other' }, { selected: false, content: t('screenTabs:shared.report.reasons.violation'), type: 'violation' } ]) const [rules, setRules] = useState<{ selected: boolean; content: string; id: string }[]>([]) const [forward, setForward] = useState(true) const [comment, setComment] = useState('') const [isReporting, setIsReporting] = useState(false) useEffect(() => { navigation.setOptions({ title: t('screenTabs:shared.report.name', { acct: `@${account.acct}` }), headerLeft: () => ( navigation.goBack()} /> ), headerRight: () => ( { const body: { status_ids?: string[] account_id?: string comment?: string forward?: boolean category?: string rule_ids?: string[] } = {} if (status) { if (status._remote) { const fetchedStatus = await searchLocalStatus(status.uri) if (fetchedStatus) { body.status_ids = [fetchedStatus.id] } } else { body.status_ids = [status.id] } } body.account_id = account.id comment.length && (body.comment = comment) body.forward = forward body.category = categories.find(category => category.selected)?.type || 'other' body.rule_ids = rules.filter(rule => rule.selected).map(rule => rule.id) apiInstance({ method: 'post', url: 'reports', body }) .then(() => { setIsReporting(false) navigation.pop(1) }) .catch(() => { setIsReporting(false) }) }} loading={isReporting} /> ) }) }, [isReporting, comment, forward, categories, rules, account.id]) const localInstance = account?.acct.includes('@') ? account?.acct.includes(`@${getAccountStorage.string('auth.account.domain')}`) : true const rulesQuery = useRulesQuery() useEffect(() => { if (rulesQuery.data) { setRules(rulesQuery.data.map(rule => ({ ...rule, selected: false, content: rule.text }))) } }, [rulesQuery.data]) return ( {!localInstance ? ( {t('screenTabs:shared.report.forward.heading', { instance: account.acct.match(/@(.*)/)?.[1] })} ) : null} {categories[1].selected || comment.length ? ( <> {t('screenTabs:shared.report.comment.heading')} {comment.length} / 1000 ) : null} {rules.length ? ( ) : null} ) } export default TabSharedReport