File size: 1,750 Bytes
6086e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useEffect } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import BootScreen from './components/boot/BootScreen';
import AppShell from './components/layout/AppShell';
import useChatStore from './store/useChatStore';
import { fetchHealth, fetchSchema } from './api/client';

export default function App() {
  const booted = useChatStore(s => s.booted);
  const setHealth = useChatStore(s => s.setHealth);
  const setSchemaTables = useChatStore(s => s.setSchemaTables);

  // Poll health every 30 seconds after boot
  useEffect(() => {
    if (!booted) return;
    const poll = async () => {
      const t0 = performance.now();
      try {
        const h = await fetchHealth();
        setHealth({ status: h.status === 'healthy' ? 'healthy' : 'degraded', latency: Math.round(performance.now() - t0) });
      } catch {
        setHealth({ status: 'offline', latency: null });
      }
    };
    poll();
    const id = setInterval(poll, 30_000);
    return () => clearInterval(id);
  }, [booted, setHealth]);

  // Load schema after boot
  useEffect(() => {
    if (!booted) return;
    fetchSchema().then(d => { if (d.tables) setSchemaTables(d.tables); }).catch(() => {});
  }, [booted, setSchemaTables]);

  return (
    <div className="h-full w-full overflow-hidden">
      <AnimatePresence mode="wait">
        {!booted
          ? <BootScreen key="boot" />
          : (
            <motion.div
              key="app"
              initial={{ opacity: 0 }}
              animate={{ opacity: 1 }}
              transition={{ duration: 0.4 }}
              className="h-full w-full"
            >
              <AppShell />
            </motion.div>
          )
        }
      </AnimatePresence>
    </div>
  );
}