// Entry detail screen — with threaded comments function EntryScreen({ entry, onBack, user }) { const { ENCOUNTER_TYPES } = window.ARCHIVE; // Build the per-entry list of category metas — supports multi-category // entries while staying compatible with legacy single-`type` entries. const categoryIds = Array.isArray(entry.types) && entry.types.length > 0 ? entry.types : (entry.type ? [entry.type] : []); const typeMetas = categoryIds.map(id => ENCOUNTER_TYPES.find(t => t.id === id)).filter(Boolean); const typeMeta = typeMetas[0] || {}; const acc = window.entryAccent(entry); const [vote, setVote] = React.useState(null); const [newThread, setNewThread] = React.useState(''); const [threads, setThreads] = React.useState([]); const [replyingTo, setReplyingTo] = React.useState(null); const [replyBody, setReplyBody] = React.useState(''); const [witnesses, setWitnesses] = React.useState(entry.witnesses); const [believeCount, setBelieveCount] = React.useState(entry.believe); const [skepticalCount, setSkepticalCount] = React.useState(entry.skeptical); // Attached files come from the single-entry endpoint (list responses // don't include them). Starts with whatever the passed entry carries. const [files, setFiles] = React.useState(Array.isArray(entry.files) ? entry.files : []); const [thumbnail, setThumbnailUrl] = React.useState(entry.thumbnail || null); const [copied, setCopied] = React.useState(false); // The picture open in the full-size viewer (null = closed). const [viewing, setViewing] = React.useState(null); React.useEffect(() => { if (!viewing) return; const onKey = (e) => { if (e.key === 'Escape') setViewing(null); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [viewing]); // Phones get the system share sheet; elsewhere the link is copied. const share = async () => { const url = window.location.origin + window.entryPath(entry); try { if (navigator.share) { await navigator.share({ title: entry.title, url }); return; } await navigator.clipboard.writeText(url); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { /* share sheet dismissed */ } }; const hasCoords = Number.isFinite(entry.lat) && Number.isFinite(entry.lng); const authorName = entry.author_name || entry.author || 'anonymous'; // Load comments + full record (files) from API React.useEffect(() => { window.api.getComments(entry.id).then(data => { setThreads(data.threads || []); }).catch(err => console.warn('Could not load comments:', err)); window.api.getEntry(entry.id).then(full => { if (Array.isArray(full.files)) setFiles(full.files); if (full.thumbnail) setThumbnailUrl(full.thumbnail); }).catch(err => console.warn('Could not load entry files:', err)); }, [entry.id]); // Evidence = images/video; anything else lands in the documents table. const isMedia = (f) => /^(image|video)\//.test(f.mime_type || f.mime || ''); const evidence = files.filter(isMedia); const documents = files.filter(f => !isMedia(f)); const fmtSize = (s) => { const n = parseInt(s, 10); if (!Number.isFinite(n)) return ''; if (n >= 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + ' MB'; if (n >= 1024) return Math.round(n / 1024) + ' KB'; return n + ' B'; }; const openFile = async (f) => { try { const { url } = await window.api.get(`/entries/${entry.id}/files/${f.id}/url`); window.open(url, '_blank', 'noopener'); } catch (err) { console.warn('Could not open file:', err); } }; // The full account, split into paragraphs. Falls back to the summary // for entries submitted without a long-form narrative. const paragraphs = (entry.full_account || '') .split(/\n+/).map(s => s.trim()).filter(Boolean); const sig = (n) => ( {[1,2,3,4,5].map(i => )} ); const postThread = async () => { if (!newThread.trim()) return; try { const created = await window.api.postComment(entry.id, { body: newThread, author_name: user?.name || 'anonymous', author_id: user?.id || null, }); setThreads([{ ...created, author: created.author_name, time: 'just now', replies: [] }, ...threads]); setNewThread(''); } catch (err) { console.error('Post thread failed:', err); } }; const postReply = async (threadId) => { if (!replyBody.trim()) return; try { const created = await window.api.postComment(entry.id, { body: replyBody, author_name: user?.name || 'anonymous', author_id: user?.id || null, parent_id: threadId, }); setThreads(threads.map(t => t.id === threadId ? { ...t, replies: [...t.replies, { ...created, author: created.author_name, time: 'just now', replies: [] }] } : t )); setReplyBody(''); setReplyingTo(null); } catch (err) { console.error('Post reply failed:', err); } }; return (
{/* Meta header */}
← BACK TO ARCHIVE / ENTRY {entry.id} / FILED BY {authorName.toUpperCase()}
◷ {window.formatDate(entry.date)}{entry.time ? ` · ${entry.time}` : ''} {hasCoords && ⌖ {entry.lat.toFixed(3)}°, {entry.lng.toFixed(3)}°}
{/* Hero */} {/* With a picture, its column is exactly as wide as the picture at 440px high (capped at 60% of the page); the title panel takes the rest. */}
{thumbnail ? (
{entry.title} setViewing({ url: thumbnail, name: entry.title })} style={{ display: 'block', height: 440, width: 'auto', maxWidth: '60vw', objectFit: 'contain', cursor: 'zoom-in' }} /> {entry.id}
) : ( {entry.id} )}
{typeMetas.map((m, i) => ( {m.icon} {m.label} ))} {entry.tags.map(t => #{t})}

{entry.title}

{entry.summary}
{/* Evidence grid */}
THE ACCOUNT
{paragraphs.length > 0 ? paragraphs.map((p, i) =>

{p}

) :

{entry.summary}

}
{/* Attached evidence — hidden entirely for text-only reports */} {evidence.length > 0 && ( <>
ATTACHED EVIDENCE · {evidence.length} FILE{evidence.length === 1 ? '' : 'S'}
{/* One row height; each picture's width follows its own proportions, so there's no empty space beside it. Rows wrap on narrow screens. */}
{evidence.map(f => { const showable = f.url && /^image\/(jpeg|png|webp|gif)$/.test(f.mime_type || ''); return showable ? ( {f.name} setViewing(f)} style={{ height: 200, width: 'auto', maxWidth: '100%', objectFit: 'contain', display: 'block', cursor: 'zoom-in', background: 'var(--bg-2)', border: '1px solid var(--line)' }} /> ) : (
openFile(f)}>
); })}
)} {/* Supporting documents — non-media attachments */} {documents.length > 0 && ( <>
SUPPORTING DOCUMENTS · {documents.length} ATTACHED
Submitter attached the following documents to corroborate the account. Click to open.
{documents.map((d, i) => { const ext = (d.name || '').split('.').pop().slice(0, 4).toUpperCase() || 'FILE'; return (
openFile(d)} style={{ display: 'grid', gridTemplateColumns: '44px 1fr 100px 80px', gap: 16, padding: '14px 18px', borderTop: i === 0 ? 'none' : '1px solid var(--line)', alignItems: 'center', cursor: 'pointer', transition: 'background 0.12s' }} onMouseEnter={e => e.currentTarget.style.background = 'var(--bg-2)'} onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
{ext}
{d.name}
{d.mime_type || ''}
{fmtSize(d.size)} VIEW ↗
); })}
)}
{/* Right rail — facts */}
{/* Mini map — only when the report has coordinates */} {hasCoords && (
WHERE
)} {/* Discussion */}
DISCUSSION · {threads.length} THREADS

Community analysis

Each comment opens its own thread — replies stay nested
{/* New thread composer */}
Start a new thread