// ============================================================ // Mobile — Report (with auto-save), Posts, Home/Site, Terms // Loads after profile-v2.jsx // ============================================================ const CATS_V2 = ["Roads", "Water", "Power", "Safety", "Civic Infrastructure", "Cultural Wealth", "Other"]; // ============================ REPORT SCREEN ============================ function ReportScreen({ editing, onSaveDraft, onSubmit, onDelete, onDirty }) { const isEdit = editing && editing.id != null; const [lang, setLang] = React.useState("en"); const [title, setTitle] = React.useState(editing?.title || ""); const [desc, setDesc] = React.useState(editing?.body || ""); const [cat, setCat] = React.useState(editing?.cat || "Roads"); const [loc, setLoc] = React.useState(editing?.location || "Kanchipuram, TN"); const [dirty, setDirtyLocal] = React.useState(false); const [autoSaved, setAutoSaved] = React.useState(null); const [saving, setSaving] = React.useState(false); const initRef = React.useRef(JSON.stringify({ title: editing?.title || "", desc: editing?.body || "", cat: editing?.cat || "Roads", loc: editing?.location || "Kanchipuram, TN", })); const autoSaveTimer = React.useRef(null); React.useEffect(() => { const isDirty = JSON.stringify({ title, desc, cat, loc }) !== initRef.current; setDirtyLocal(isDirty); onDirty && onDirty(isDirty); // auto-save after 3 seconds of inactivity if (isDirty && title.trim().length > 3) { clearTimeout(autoSaveTimer.current); autoSaveTimer.current = setTimeout(() => { setSaving(true); setTimeout(() => { setSaving(false); const now = new Date(); setAutoSaved(now.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })); }, 600); }, 3000); } return () => clearTimeout(autoSaveTimer.current); }, [title, desc, cat, loc]); const payload = () => ({ title: title.trim(), body: desc.trim(), cat, location: loc.trim() }); const canSubmit = title.trim().length > 3 && desc.trim().length > 8; const L = { en: { head: "Headline", desc: "Description", cat: "Category", loc: "Location", hph: "What happened?", dph: "Describe the situation on the ground…" }, ta: { head: "தலைப்பு", desc: "விவரம்", cat: "வகை", loc: "இடம்", hph: "என்ன நடந்தது?", dph: "நிலைமையை விளக்குங்கள்…" }, }[lang]; return (
{/* header + auto-save */}

{isEdit ? "Edit article" : "Report a Story"}

{isEdit && }
{[["ta", "தமிழ்"], ["en", "EN"]].map(([k, l]) => ( ))}
{/* requested-changes banner */} {isEdit && editing.status === "CHANGES REQ." && editing.note && (
Editor requested changes
{editing.note}
)} setTitle(e.target.value)} style={nkInput} placeholder={L.hph} />