import { getHealth } from '../../api/client'; import { cn } from '../../lib/utils'; import type { ReactNode } from 'react'; import { useEffect, useState } from 'react'; import { Header } from './Header'; export interface LayoutProps { children: ReactNode; className?: string; } type ApiStatus = 'checking' | 'online' | 'offline'; const STATUS_STYLES: Record = { checking: 'bg-amber-400', online: 'bg-green-500', offline: 'bg-red-500', }; /** * Application shell: sticky header, routed page content, and a footer with a * backend API status indicator (fetched from `GET /api/v1/health` on mount). */ export function Layout({ children, className }: LayoutProps) { const [apiStatus, setApiStatus] = useState('checking'); useEffect(() => { let active = true; getHealth() .then(() => { if (active) setApiStatus('online'); }) .catch(() => { if (active) setApiStatus('offline'); }); return () => { active = false; }; }, []); return (
{children}
); } export default Layout;