import { useState, useEffect } from 'react' import { fetchEntryDetail } from '../api' import PreviewPanel from './PreviewPanel' // Standalone full-page preview — rendered when the URL is /preview/:archiveId/:entryUid. // Auth uses the existing session cookie; no login flow needed here since the // main app will have set one. export default function PreviewPage({ archiveId, entryUid }) { const [detail, setDetail] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) // Set to true by ArticleRenderer when the entry turns out to be an X article, // triggering the X dark palette on the page shell. const [xArticle, setXArticle] = useState(false) // When displaying an X article, make the document scroll (not an inner div) // and apply color-scheme:dark so native scrollbars match the dark palette. useEffect(() => { if (!xArticle) return const html = document.documentElement const body = document.body const prevScheme = html.style.colorScheme const prevBg = body.style.background html.style.colorScheme = 'dark' body.style.background = '#000' return () => { html.style.colorScheme = prevScheme body.style.background = prevBg } }, [xArticle]) useEffect(() => { setXArticle(false) fetchEntryDetail(archiveId, entryUid) .then(d => { setDetail(d); setLoading(false) }) .catch(e => { setError(e?.message || 'Failed to load entry'); setLoading(false) }) }, [archiveId, entryUid]) const title = detail?.summary?.title || entryUid const originalUrl = detail?.summary?.original_url return (