import { useEffect, useState } from 'react'; import { DocumentScreen } from './screens/document'; import { LibraryScreen } from './screens/library'; import { ShareDialog } from './share/ShareDialog'; import { useRoute } from './state/route'; import { StoreProvider, useStore } from './state/store'; import { Badge, cx, Spinner } from './ui/primitives'; export function App() { return ( ); } function Shell() { const { config, documents, loading, error } = useStore(); const [route, navigate] = useRoute(); // Transient UI, so it stays out of the URL — `?share=` already means "which // identity is VIEWING", and overloading it would conflate two ideas. const [sharingDocId, setSharingDocId] = useState(null); if (loading) { return (
Connecting to CloudPDF…
); } if (!config) { return (

Can’t reach the demo API.

{error ?? 'Is `pnpm dev` running?'}

); } return (
navigate({ docId: null, shareId: null })} />
{route.docId ? ( navigate({ docId: null, shareId: null })} onShare={() => setSharingDocId(route.docId)} onSelectShare={(shareId) => navigate({ shareId })} /> ) : ( navigate({ docId, shareId: null })} onShare={(docId) => setSharingDocId(docId)} /> )}
{sharingDocId && ( d.id === sharingDocId)?.name ?? sharingDocId} onClose={() => setSharingDocId(null)} onCreated={(share) => { setSharingDocId(null); // Land on the document AS the person you just invited — the whole // point is seeing the scopes you picked take effect. navigate({ docId: share.docId, shareId: share.id }); }} /> )}
); } function TopBar({ tenantId, onHome }: { tenantId: string; onHome: () => void }) { return (
/ {tenantId} Rendering runs on the server — no PDF engine in this bundle.
); } /** Round trips the dev server can add to every `/v1` request. */ const LATENCY_PRESETS = [ { label: 'No added latency', ms: 0, jitter: 0 }, { label: '+150 ms', ms: 150, jitter: 0 }, { label: '+500 ms', ms: 500, jitter: 0 }, { label: '+300–700 ms (out of order)', ms: 300, jitter: 400 }, { label: '+1 s', ms: 1000, jitter: 0 }, { label: '+2 s', ms: 2000, jitter: 0 }, ]; /** * Slow the network down on purpose, to see what the viewer does at a real * round trip. The delay is held by the Vite dev server (`/__latency`), so the * picker is absent in a production build. */ function LatencyPicker() { const [current, setCurrent] = useState<{ ms: number; jitter: number } | null>(null); useEffect(() => { fetch('/__latency') .then((res) => (res.ok ? res.json() : null)) .then(setCurrent) .catch(() => setCurrent(null)); }, []); if (!current) return null; const selected = LATENCY_PRESETS.findIndex( (p) => p.ms === current.ms && p.jitter === current.jitter, ); return ( ); } function CloudMark({ className }: { className?: string }) { return ( ); }