/** * EventProof — renders one cached event from /api/events as broker proof. * * This is the Phase 1 landing page's broker-proof component: it shows a * single cached event title and date, confirming the CalDAV broker has * successfully fetched and cached at least one real Fastmail event (CAL-01). * * Data flow: * React Query ['events'] → fetchEvents() → GET /api/events * → renders first event's summary (parsed from rawVevent) and date * * Empty state: "No cached events yet" — shown when the poller hasn't run yet. * This is expected on first boot before any Fastmail credentials are loaded. */ import { useQuery } from '@tanstack/react-query' // fetchEventsLegacy: Phase 1 broker-proof; replaced by windowed fetchEvents in Plan 04. // This component is removed in Plan 05. import { fetchEventsLegacy, type CalendarEvent } from '../api/client' import ICAL from 'ical.js' /** * Extracts the event summary (title) from a raw VCALENDAR/VEVENT string. * Falls back to 'Untitled event' if parsing fails or SUMMARY is absent. */ function extractSummary(rawVevent: string): string { try { const parsed = ICAL.parse(rawVevent) const comp = new ICAL.Component(parsed) const vevent = comp.getFirstSubcomponent('vevent') if (!vevent) return 'Untitled event' return (vevent.getFirstPropertyValue('summary') as string | null) ?? 'Untitled event' } catch { return 'Untitled event' } } /** * Formats the event date for display. * Uses dtstartDate (for all-day) or dtstartUtc (for timed events). */ function formatDate(event: CalendarEvent): string { if (event.allDay && event.dtstartDate) { return event.dtstartDate } if (event.dtstartUtc) { try { return new Date(event.dtstartUtc).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric', }) } catch { return event.dtstartUtc } } return 'Date unknown' } export function EventProof() { const eventsQuery = useQuery({ queryKey: ['events-legacy'], queryFn: fetchEventsLegacy, retry: false, staleTime: 5 * 60 * 1000, // 5 min — matches broker poll interval }) if (eventsQuery.isLoading) { return (