File size: 3,375 Bytes
23d418f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { ShieldCheck } from 'lucide-react'
import { lazy, Suspense } from 'react'
import { BrowserRouter, Navigate, NavLink, Route, Routes } from 'react-router'
import { ChatProvider } from '@/hooks/ChatProvider'
import { cn } from '@/lib/utils'
import { AskPage } from '@/pages/AskPage'
import { AboutPage } from '@/pages/AboutPage'

// The Evals page carries the chart library (~150 kB gzip): loaded only when opened, so
// the chat stays light.
const EvalsPage = lazy(() => import('@/pages/EvalsPage').then((m) => ({ default: m.EvalsPage })))
// The Architecture page carries the graph library: also loaded only when opened.
const ArchitecturePage = lazy(() => import('@/pages/ArchitecturePage').then((m) => ({ default: m.ArchitecturePage })))

const PAGES = [
  { to: '/ask', label: 'Ask' },
  { to: '/evals', label: 'Evals' },
  { to: '/architecture', label: 'Architecture' },
  { to: '/about', label: 'About' },
]

/** The shell: a slim header with the pages, then the page filling the rest of the screen
 * (the Ask page is a full-height chat). The server sends index.html for any of these
 * paths (api.SpaFiles), so a reload keeps the page. */
export default function App() {
  return (
    <BrowserRouter>
      <ChatProvider>
        <div className="flex h-dvh flex-col bg-background text-foreground">
          <header className="shrink-0 border-b">
            <div className="mx-auto flex max-w-6xl items-center gap-6 px-4 py-2.5">
              <NavLink to="/ask" className="flex items-center gap-2 font-semibold">
                <ShieldCheck className="size-5 text-primary" />
                <span className="hidden sm:inline">CoverageCheck</span>
              </NavLink>
              <nav className="flex gap-1 text-sm">
                {PAGES.map((p) => (
                  <NavLink
                    key={p.to}
                    to={p.to}
                    className={({ isActive }) =>
                      cn(
                        'rounded-md px-3 py-1.5',
                        isActive ? 'bg-accent font-medium text-accent-foreground' : 'text-muted-foreground hover:text-foreground',
                      )
                    }
                  >
                    {p.label}
                  </NavLink>
                ))}
              </nav>
            </div>
          </header>
          <main className="min-h-0 flex-1">
            <Routes>
              <Route path="/" element={<Navigate to="/ask" replace />} />
              <Route path="/ask" element={<AskPage />} />
              <Route
                path="/evals"
                element={
                  <Suspense fallback={<div className="p-8 text-sm text-muted-foreground">Loading the results…</div>}>
                    <EvalsPage />
                  </Suspense>
                }
              />
              <Route
                path="/architecture"
                element={
                  <Suspense fallback={<div className="p-8 text-sm text-muted-foreground">Loading the architecture…</div>}>
                    <ArchitecturePage />
                  </Suspense>
                }
              />
              <Route path="/about" element={<AboutPage />} />
              <Route path="*" element={<Navigate to="/ask" replace />} />
            </Routes>
          </main>
        </div>
      </ChatProvider>
    </BrowserRouter>
  )
}