import { useEffect, useMemo, useState } from 'react'; import { Link, useNavigate, useParams } from 'react-router-dom'; import { fetchEntry } from '../api'; import VideoPlayer from '../components/VideoPlayer'; import { ConversationPanel, GrammarPanel, KeyPhrasePanel, VocabPanel } from '../components/ItemPanels'; import ExpandableText from '../components/ExpandableText'; import type { EntryDetail } from '../types'; export default function EntryPage() { const { idEncoded } = useParams(); const navigate = useNavigate(); const [entry, setEntry] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const entryId = useMemo(() => { try { return decodeURIComponent(idEncoded || ''); } catch { return idEncoded || ''; } }, [idEncoded]); useEffect(() => { if (!entryId) return; setLoading(true); fetchEntry(entryId) .then((data) => setEntry(data)) .catch(() => setError('Entry not found')) .finally(() => setLoading(false)); }, [entryId]); if (!entryId) { return
No entry id provided.
; } if (loading) return
Loading entry…
; if (error || !entry) return
{error || 'Entry not found.'}
; const counts = entry.counts || { grammar: 0, vocab: 0, key_phrases: 0, conversation: 0, quiz: 0 }; const quizLink = `/quiz?mode=entry&id=${encodeURIComponent(entry.id)}`; const ig = entry.ig_meta; const profileUrl = ig?.post_url || ig?.profile_url || (ig?.username ? `https://www.instagram.com/${ig.username}/` : undefined); let postDate: string | undefined; if (ig?.post_date) { const parsed = new Date(ig.post_date); postDate = isNaN(parsed.getTime()) ? ig.post_date : parsed.toLocaleString(); } return (

{entry.meta?.mode || 'mode not set'}

{entry.title}

{entry.meta?.type}

Grammar {counts.grammar} Vocab {counts.vocab} Phrases {counts.key_phrases} Conversation {counts.conversation} Quiz {counts.quiz}
Start quiz (this entry)
{ig && (
{ig.profile_pic_url ? ( {ig.username { if (ig.profile_pic_url && !e.currentTarget.dataset.fallback) { e.currentTarget.dataset.fallback = '1'; e.currentTarget.src = ig.profile_pic_url; } }} /> ) : (
)}
{ig.username ? ( {ig.username} ) : ( Instagram )} {ig.full_name && · {ig.full_name}}
{postDate || ig.post_date || 'Date unknown'}
{ig.description && ( )}
)}
Mode
{entry.meta?.mode || 'n/a'}
Type
{entry.meta?.type || 'n/a'}
Entry ID
{entry.id}
); }