import './report-modal.css'; import { msg, t, Trans } from '@lingui/macro'; import { useLingui } from '@lingui/react'; import { Fragment } from 'preact'; import { useMemo, useRef, useState } from 'preact/hooks'; import { api } from '../utils/api'; import showToast from '../utils/show-toast'; import { getCurrentInstance } from '../utils/store-utils'; import AccountBlock from './account-block'; import Icon from './icon'; import Loader from './loader'; import Status from './status'; // NOTE: `dislike` hidden for now, it's actually not used for reporting // Mastodon shows another screen for unfollowing, muting or blocking instead of reporting const CATEGORIES = [, /*'dislike'*/ 'spam', 'legal', 'violation', 'other']; // `violation` will be set if there are `rule_ids[]` const CATEGORIES_INFO = { // dislike: { // label: 'Dislike', // description: 'Not something you want to see', // }, spam: { label: msg`Spam`, description: msg`Malicious links, fake engagement, or repetitive replies`, }, legal: { label: msg`Illegal`, description: msg`Violates the law of your or the server's country`, }, violation: { label: msg`Server rule violation`, description: msg`Breaks specific server rules`, stampLabel: msg`Violation`, }, other: { label: msg`Other`, description: msg`Issue doesn't fit other categories`, excludeStamp: true, }, }; function ReportModal({ account, post, onClose }) { const { _ } = useLingui(); const { masto } = api(); const [uiState, setUIState] = useState('default'); const [username, domain] = account.acct.split('@'); const [rules, currentDomain] = useMemo(() => { const { rules, domain } = getCurrentInstance(); return [rules || [], domain]; }); const [selectedCategory, setSelectedCategory] = useState(null); const [showRules, setShowRules] = useState(false); const rulesRef = useRef(null); const [hasRules, setHasRules] = useState(false); return (

{post ? t`Report Post` : t`Report @${username}`}

{post ? ( ) : ( )}
{!!selectedCategory && !CATEGORIES_INFO[selectedCategory].excludeStamp && ( )}
{ e.preventDefault(); const formData = new FormData(e.target); const entries = Object.fromEntries(formData.entries()); console.log('ENTRIES', entries); let { category, comment, forward } = entries; if (!comment) comment = undefined; if (forward === 'on') forward = true; const ruleIds = category === 'violation' ? Object.entries(entries) .filter(([key]) => key.startsWith('rule_ids')) .map(([key, value]) => value) : undefined; const params = { category, comment, forward, ruleIds, }; console.log('PARAMS', params); setUIState('loading'); (async () => { try { await masto.v1.reports.create({ accountId: account.id, statusIds: post?.id ? [post.id] : undefined, category, comment, ruleIds, forward, }); setUIState('success'); showToast(post ? t`Post reported` : t`Profile reported`); onClose(); } catch (error) { console.error(error); setUIState('error'); showToast( error?.message || (post ? t`Unable to report post` : t`Unable to report profile`), ); } })(); }} >

{post ? t`What's the issue with this post?` : t`What's the issue with this profile?`}

{CATEGORIES.map((category) => category === 'violation' && !rules?.length ? null : ( {category === 'violation' && !!rules?.length && ( )} ), )}