import { useState, useEffect, useRef } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFlag, faXmark } from '@fortawesome/free-solid-svg-icons'; import { atprotoClient } from '../api/client'; import type { PostView } from '../api/types'; import './ReportModal.css'; interface ReportModalProps { post: PostView; onClose: () => void; } const REPORT_REASONS = [ { value: 'com.atproto.moderation.defs#reasonSpam', label: 'Spam' }, { value: 'com.atproto.moderation.defs#reasonViolation', label: 'Violation of server rules' }, { value: 'com.atproto.moderation.defs#reasonMisleading', label: 'Misleading content' }, { value: 'com.atproto.moderation.defs#reasonSexual', label: 'Unwanted sexual content' }, { value: 'com.atproto.moderation.defs#reasonRude', label: 'Anti-social behavior' }, { value: 'com.atproto.moderation.defs#reasonOther', label: 'Other' }, ] as const; export default function ReportModal({ post, onClose }: ReportModalProps) { const [reasonType, setReasonType] = useState(''); const [details, setDetails] = useState(''); const [submitting, setSubmitting] = useState(false); const [submitted, setSubmitted] = useState(false); const [error, setError] = useState(null); const modalRef = useRef(null); useEffect(() => { const prev = document.body.style.overflow; document.body.style.overflow = 'hidden'; return () => { document.body.style.overflow = prev; }; }, []); useEffect(() => { const handleKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', handleKey); return () => window.removeEventListener('keydown', handleKey); }, [onClose]); const handleSubmit = async () => { if (!reasonType || submitting) return; setSubmitting(true); setError(null); try { await atprotoClient.createReport({ reasonType, reason: details.trim() || undefined, subject: { $type: 'com.atproto.repo.strongRef', uri: post.uri, cid: post.cid, }, }); setSubmitted(true); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to submit report'); } finally { setSubmitting(false); } }; const handleBackdropClick = (e: React.MouseEvent) => { if (e.target === modalRef.current) onClose(); }; return (

Report Post

{submitted ? (

Report submitted. Thank you for helping keep the community safe.

) : ( <>

Why are you reporting this post?

{REPORT_REASONS.map((r) => ( ))}