// Submit screens — photo flow & story-only flow // ───────────────────────────────────────────────────────────── // LocationPicker — a map you click to drop the report's pin. `focus` // changes when the pin was set from outside (a place search), and the map // flies there; clicks report back through onPick. // ───────────────────────────────────────────────────────────── function LocationPicker({ lat, lng, focus, onPick, height = 300 }) { const ref = React.useRef(null); const mapRef = React.useRef(null); const markerRef = React.useRef(null); const onPickRef = React.useRef(onPick); onPickRef.current = onPick; React.useEffect(() => { const map = L.map(ref.current, { center: [25, 10], zoom: 2, minZoom: 1, maxZoom: 18, worldCopyJump: true }); L.maplibreGL({ style: 'https://tiles.openfreemap.org/styles/dark', attribution: 'OpenFreeMap © OpenStreetMap', }).addTo(map); map.on('click', e => onPickRef.current(e.latlng.lat, ((e.latlng.lng + 540) % 360) - 180)); map.getContainer().style.cursor = 'crosshair'; mapRef.current = map; return () => { map.remove(); mapRef.current = null; markerRef.current = null; }; }, []); const la = parseFloat(lat), ln = parseFloat(lng); const has = Number.isFinite(la) && Number.isFinite(ln); React.useEffect(() => { const map = mapRef.current; if (!map) return; if (!has) { if (markerRef.current) { markerRef.current.remove(); markerRef.current = null; } return; } const icon = L.divIcon({ className: '', iconSize: [16, 16], iconAnchor: [8, 8], html: '
' }); if (markerRef.current) markerRef.current.setLatLng([la, ln]); else markerRef.current = L.marker([la, ln], { icon }).addTo(map); }, [la, ln, has]); // A searched place: fly there (clicks don't move the map). React.useEffect(() => { if (focus && has && mapRef.current) mapRef.current.flyTo([la, ln], 11, { duration: 0.8 }); }, [focus]); return
; } // Place names <-> coordinates, from OpenStreetMap's Nominatim (free, no key). // Optional: if it's unreachable the form still works with a typed place. const NOMINATIM = 'https://nominatim.openstreetmap.org'; async function findPlace(query) { const r = await fetch(`${NOMINATIM}/search?format=jsonv2&limit=1&accept-language=en&q=${encodeURIComponent(query)}`); const [hit] = await r.json(); return hit ? { lat: parseFloat(hit.lat), lng: parseFloat(hit.lon) } : null; } async function nameOfPlace(lat, lng) { const r = await fetch(`${NOMINATIM}/reverse?format=jsonv2&zoom=10&accept-language=en&lat=${lat}&lon=${lng}`); const a = (await r.json()).address || {}; return [a.city || a.town || a.village || a.municipality || a.county, a.state, a.country].filter(Boolean).join(', '); } const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; function SubmitScreen({ mode = 'photo', onNav, user, onSubmitted }) { const { ENCOUNTER_TYPES } = window.ARCHIVE; // `types` is an ordered list — first item is the primary category. // An incident may belong to several (e.g. "Missing time" + "Crop circles"). const blankForm = { types: [], title: '', summary: '', full_account: '', time: '', // The date as parts: the year is enough, month and day only if known. year: '', month: '', day: '', place: '', lat: '', lng: '', device: '', witnesses: 1, tags: '', anonymous: !user, }; // Drafts: everything typed is kept in this browser (per flow and account) // until the report is submitted, so a closed tab or a reload loses nothing. // Files can't be kept that way; the banner asks for them again. const draftKey = `openufoarchive:draft:${mode}:${user?.id || 'anon'}`; const [draft] = React.useState(() => { try { const d = JSON.parse(localStorage.getItem(draftKey)); return d && d.form ? d : null; } catch { return null; } }); const [showDraftNote, setShowDraftNote] = React.useState(!!draft); const [step, setStep] = React.useState(draft ? draft.step || 1 : 1); const [form, setForm] = React.useState(draft ? { ...blankForm, ...draft.form } : blankForm); const [pinFocus, setPinFocus] = React.useState(0); const [placeMsg, setPlaceMsg] = React.useState(''); const [dragOver, setDragOver] = React.useState(false); const [submitting, setSubmitting] = React.useState(false); // Real File objects, wrapped with display metadata. const [files, setFiles] = React.useState([]); // Supporting documents — available in BOTH flows. // Corroborating material: police reports, newspaper clippings, affidavits, // medical records, radar logs, shortwave recordings, etc. const [docs, setDocs] = React.useState([]); // The picture shown on the archive's cards (a File from files or docs). // Defaults to the first picture attached. const [thumbFile, setThumbFile] = React.useState(null); const fileInputRef = React.useRef(null); const thumbInputRef = React.useRef(null); const update = (k, v) => setForm({ ...form, [k]: v }); const hasContent = form.title || form.summary || form.full_account || form.types.length > 0 || form.place; React.useEffect(() => { try { if (hasContent) { localStorage.setItem(draftKey, JSON.stringify({ form, step, fileCount: files.length + docs.length, savedAt: Date.now(), })); } } catch { /* storage full or blocked: drafts are a convenience */ } }, [form, step, files.length, docs.length]); const clearDraft = () => { try { localStorage.removeItem(draftKey); } catch {} }; const startOver = () => { clearDraft(); setForm(blankForm); setStep(1); setFiles([]); setDocs([]); setThumbFile(null); setShowDraftNote(false); }; const humanSize = (bytes) => { if (!Number.isFinite(bytes)) return ''; if (bytes >= 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(1) + ' MB'; if (bytes >= 1024) return (bytes / 1024).toFixed(0) + ' KB'; return bytes + ' B'; }; // Pictures every browser can show; only these can be the thumbnail. const isPicture = (type) => /^image\/(jpeg|png|webp|gif)$/.test(type || ''); const wrapFiles = (fileList) => Array.from(fileList || []).map(f => ({ name: f.name, size: humanSize(f.size), type: f.type, file: f, preview: isPicture(f.type) ? URL.createObjectURL(f) : null, })); // One upload area for everything: photos, video and audio show as tiles, // anything else (PDF, Word, text…) goes in the documents list. At most 10 // files per report (one upload request). const MAX_FILES = 10; const isMedia = (type) => /^(image|video|audio)\//.test(type || ''); const addAttachments = (fileList) => { const room = MAX_FILES - files.length - docs.length; const added = wrapFiles(fileList).slice(0, Math.max(0, room)); setFiles(prev => [...prev, ...added.filter(w => isMedia(w.type))]); setDocs(prev => [...prev, ...added.filter(w => !isMedia(w.type))]); }; // "1989", "1989-05" or "1989-05-14" from the parts. const pad = (n) => String(n).padStart(2, '0'); const dateValue = () => !/^\d{4}$/.test(form.year) ? '' : form.year + (form.month ? '-' + pad(form.month) + (form.day ? '-' + pad(form.day) : '') : ''); const daysIn = (y, m) => new Date(parseInt(y, 10) || 2000, m, 0).getDate(); const thisYear = new Date().getFullYear(); const yearOk = /^\d{4}$/.test(form.year) && +form.year >= 1000 && +form.year <= thisYear; // Map pin: clicking sets it; if no place was typed yet, name it too. const pickOnMap = (lat, lng) => { setForm(prev => ({ ...prev, lat: lat.toFixed(5), lng: lng.toFixed(5) })); if (!form.place.trim()) { nameOfPlace(lat, lng).then(name => name && setForm(prev => prev.place.trim() ? prev : { ...prev, place: name })).catch(() => {}); } }; const searchPlace = async () => { if (!form.place.trim()) return setPlaceMsg('Type a place first'); setPlaceMsg('Searching…'); try { const hit = await findPlace(form.place); if (!hit) return setPlaceMsg('Not found: click the map instead'); setForm(prev => ({ ...prev, lat: hit.lat.toFixed(5), lng: hit.lng.toFixed(5) })); setPinFocus(n => n + 1); setPlaceMsg('Pinned: click the map to adjust'); } catch { setPlaceMsg('Search unavailable: click the map instead'); } }; const pictures = [...files, ...docs].filter(w => w.preview); const thumb = pictures.find(w => w.file === thumbFile) || pictures[0] || null; // A picture tile: fixed height, width follows the picture. Tapping it // makes it the thumbnail. const PictureTile = ({ w, height }) => (
setThumbFile(w.file)} style={{ position: 'relative', cursor: 'pointer', maxWidth: '100%' }}> {w.name} {thumb === w && ★ THUMBNAIL}
); // Toggle a category in/out of the selected set, preserving selection order // so the first-selected category stays the primary. const toggleType = (id) => { setForm(prev => { const list = prev.types.includes(id) ? prev.types.filter(t => t !== id) : [...prev.types, id]; return { ...prev, types: list }; }); }; const steps = [ { n: 1, label: 'What' }, { n: 2, label: mode === 'photo' ? 'Evidence' : 'The account' }, { n: 3, label: 'Where & when' }, { n: 4, label: 'Review & submit' }, ]; const LAST = steps.length; const canNext = () => { if (step === 1) return form.types.length > 0 && form.title; if (step === 2) return mode === 'photo' ? files.length > 0 : form.full_account.length > 20; if (step === 3) return yearOk && form.place.trim(); return true; }; // ── The upload area: photos, video, audio and documents in one place ── const attachments = (heading) => (
{heading}
{ addAttachments(e.target.files); e.target.value = ''; }} />
fileInputRef.current && fileInputRef.current.click()} onDragOver={e => { e.preventDefault(); setDragOver(true); }} onDragLeave={() => setDragOver(false)} onDrop={e => { e.preventDefault(); setDragOver(false); addAttachments(e.dataTransfer.files); }} style={{ padding: 40, border: '1px dashed', borderColor: dragOver ? 'var(--amber)' : 'var(--line-2)', background: dragOver ? 'rgba(220,170,80,0.04)' : 'var(--bg-1)', textAlign: 'center', cursor: 'pointer', marginBottom: 20, transition: 'all 0.15s' }}>
◬
Drop files here, or click to select
Photos · video · audio · PDF · Word · text · up to 50 MB each · {MAX_FILES} files per report
{files.length > 0 && (
{files.length} photo{files.length === 1 ? '' : 's'} / media{pictures.length > 1 ? ' · tap a picture to make it the thumbnail' : ''}
{files.map((f, i) => (
{f.preview ? :
} {/* width 0 + min-width 100%: the caption takes the tile's width instead of widening it */}
{f.name}
setFiles(files.filter((_, j) => j !== i))}>× remove
))}
)} {docs.length > 0 && (
{docs.length} document{docs.length === 1 ? '' : 's'} attached
{docs.map((d, i) => (
{(d.name && d.name.includes('.') ? d.name.split('.').pop() : 'doc').toUpperCase().slice(0, 4)}
{d.name}
{d.size}
setDocs(docs.filter((_, j) => j !== i))}>× remove
))}
Documents are published with the report as they are. Remove anything personal (names, phone numbers, IDs) before uploading.
)}
); return (
NEW SUBMISSION · {mode === 'photo' ? 'WITH PHOTO EVIDENCE' : 'TEXT ACCOUNT ONLY'}

File a report

{steps.map((s, i) => (
= s.n ? 'var(--amber)' : 'var(--line-2)', background: step === s.n ? 'var(--amber)' : 'transparent', color: step === s.n ? 'var(--bg-0)' : step > s.n ? 'var(--amber)' : 'var(--ink-2)', fontFamily: 'var(--mono)', fontSize: 12, display: 'flex', alignItems: 'center', justifyContent: 'center' }}> {step > s.n ? '✓' : s.n}
= s.n ? 'var(--ink-0)' : 'var(--ink-2)' }}>{s.label}
{i < steps.length - 1 &&
s.n ? 'var(--amber-dim)' : 'var(--line)', margin: '0 12px' }} />} ))}
{showDraftNote && (
Your draft was restored {draft.savedAt ? ` (saved ${new Date(draft.savedAt).toLocaleString()})` : ''}. {draft.fileCount > 0 ? ` Its ${draft.fileCount} attached file${draft.fileCount === 1 ? '' : 's'} need adding again.` : ''} setShowDraftNote(false)}>OK Discard and start over
)} {step === 1 && (
STEP 1 · CLASSIFY
What kind of encounter was it?
{ENCOUNTER_TYPES.map(t => { const selected = form.types.includes(t.id); const selectedIndex = form.types.indexOf(t.id); const isPrimary = selectedIndex === 0; return (
toggleType(t.id)} style={{ padding: '14px 16px', border: '1px solid', borderColor: selected ? 'var(--amber-dim)' : 'var(--line-2)', background: selected ? 'rgba(220,170,80,0.05)' : 'var(--bg-1)', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 12, position: 'relative', }}> {t.icon} {t.label} {selected && ( {isPrimary ? 'PRIMARY' : `#${selectedIndex + 1}`} )}
); })}
{form.types.length > 0 && (
SELECTED: {form.types.map((id, i) => { const meta = ENCOUNTER_TYPES.find(t => t.id === id); if (!meta) return null; return ( {i === 0 ? '★ ' : ''}{meta.icon} {meta.label} { e.stopPropagation(); toggleType(id); }}>× ); })}
)} {form.types.length === 0 &&
}
Give it a title
update('title', e.target.value)} style={{ marginBottom: 24 }} />
Tags (optional)
update('tags', e.target.value)} style={{ marginBottom: 8 }} />
Separate with commas. These help the archive cross-reference similar cases.
)} {step === 2 && mode === 'photo' && (
STEP 2 · EVIDENCE
{attachments('Photos, video, audio or documents')}
Camera or device used (if known)
update('device', e.target.value)} style={{ marginBottom: 24 }} />
What happened?