import './report-modal.css'; 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: 'Spam', description: 'Malicious links, fake engagement, or repetitive replies', }, legal: { label: 'Illegal', description: "Violates the law of your or the server's country", }, violation: { label: 'Server rule violation', description: 'Breaks specific server rules', stampLabel: 'Violation', }, other: { label: 'Other', description: "Issue doesn't fit other categories", excludeStamp: true, }, }; function ReportModal({ account, post, onClose }) { 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 ? 'Report Post' : `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 ? 'Post reported' : 'Profile reported'); onClose(); } catch (error) { console.error(error); setUIState('error'); showToast( error?.message || (post ? 'Unable to report post' : 'Unable to report profile'), ); } })(); }} >

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

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