Spaces:
Sleeping

CoverageCheck / web /src /pages /ArchitecturePage.tsx
TBM99's picture
Deploy coverage-check 3559250
23d418f verified
Raw History Blame Contribute Delete
4.46 kB
import { ChevronRight } from 'lucide-react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { Chapter } from '@/components/architecture/Chapter'
import { activeStep } from '@/lib/architecture'
import type { ArchitectureFile } from '@/lib/types'
/** How CoverageCheck works, redesigned from public guidance (owner, 9d redo): the whole
* system first as one strip of 5 steps (one level of detail), then one chapter per step,
* its text driving a small pinned diagram (scrollytelling), with System A | B | C
* compared side by side. Content: architecture.json (web/architecture.py). */
export function ArchitecturePage() {
const [data, setData] = useState<ArchitectureFile | null>(null)
const [active, setActive] = useState<{ chapter: number; step: number }>({ chapter: -1, step: -1 })
const scroller = useRef<HTMLDivElement>(null)
const steps = useRef<Map<string, HTMLElement>>(new Map()) // "chapter:step" -> element
useEffect(() => {
fetch('/data/architecture.json').then((r) => r.json()).then(setData).catch(() => setData(null))
}, [])
// the step crossing the reading line becomes active (its boxes light up)
const onScroll = useCallback(() => {
const area = scroller.current
if (!area || !data) return
const top = area.getBoundingClientRect().top
const keys: [number, number][] = []
const tops: number[] = []
data.chapters.forEach((ch, c) =>
ch.steps.forEach((_, s) => {
const el = steps.current.get(`${c}:${s}`)
if (el) {
keys.push([c, s])
tops.push(el.getBoundingClientRect().top - top)
}
}),
)
const i = activeStep(tops, area.clientHeight)
setActive(i >= 0 ? { chapter: keys[i][0], step: keys[i][1] } : { chapter: -1, step: -1 })
}, [data])
useEffect(() => {
const area = scroller.current
if (!area) return
area.addEventListener('scroll', onScroll, { passive: true })
return () => area.removeEventListener('scroll', onScroll)
}, [onScroll])
if (!data) return <div className="p-8 text-sm text-muted-foreground">Loading…</div>
return (
<div ref={scroller} className="h-full overflow-y-auto">
<div className="mx-auto max-w-6xl px-4 py-10">
<header className="mb-12 space-y-6">
<div className="max-w-2xl">
<h1 className="text-3xl font-semibold tracking-tight">How CoverageCheck works</h1>
<p className="mt-2 text-lg text-muted-foreground">
Five steps turn a broker's question into a checked answer. Three designs of the middle step are compared.
</p>
</div>
<ol className="grid gap-2 md:grid-cols-5" aria-label="The five steps">
{data.overview.map((o, i) => (
<li key={o.id} className="relative">
<a
href={`#${o.id}`}
className="flex h-full flex-col rounded-2xl border bg-background p-4 shadow-sm transition-colors hover:border-primary/60 hover:bg-accent"
>
<span className="mb-2 flex size-7 items-center justify-center rounded-full bg-primary text-sm font-semibold text-primary-foreground">
{i + 1}
</span>
<span className="font-semibold">{o.title}</span>
<span className="text-sm text-muted-foreground">{o.line}</span>
</a>
{i < data.overview.length - 1 && (
<ChevronRight className="absolute top-1/2 -right-2.5 z-10 hidden size-4 -translate-y-1/2 text-muted-foreground md:block" aria-hidden />
)}
</li>
))}
</ol>
</header>
<div className="space-y-6">
{data.chapters.map((ch, c) => (
<Chapter
key={ch.id}
chapter={ch}
number={c + 1}
active={active.chapter === c ? active.step : -1}
onStep={(s) => setActive({ chapter: c, step: s })}
stepRef={(s, el) => {
const key = `${c}:${s}`
if (el) steps.current.set(key, el)
else steps.current.delete(key)
}}
/>
))}
</div>
<p className="mt-16 border-t pt-6 text-sm text-muted-foreground">
The full results are on the Evals page; the documents and the limits are on the About page.
</p>
</div>
</div>
)
}