import { html, render, useEffect, useRef, useState } from './vendor/htm-preact.js'; import { t } from './i18n.js'; /** * Ask why a file is being reported, drawn by the page like `ask.js`. * * Resolves `{ reason, detail }`, or null when cancelled. The reasons are the * hub's own closed list (api/moderation.py `ReportRequest`), and the detail is * bounded to what the hub keeps (256 characters). */ const REASONS = ['illegal', 'spam', 'copyright', 'other']; function ReportDialog({ name, onDone }) { const [reason, setReason] = useState('illegal'); const [detail, setDetail] = useState(''); const firstRef = useRef(null); useEffect(() => { if (firstRef.current) firstRef.current.focus(); }, []); return html`
`; } export function askReport(name) { return new Promise((resolve) => { const host = document.createElement('div'); document.body.appendChild(host); const previous = document.activeElement; let settled = false; const onDone = (value) => { if (settled) return; settled = true; render(null, host); host.remove(); if (previous && previous.isConnected && typeof previous.focus === 'function') { previous.focus(); } resolve(value); }; render(html`<${ReportDialog} name=${String(name)} onDone=${onDone} />`, host); }); }