File size: 1,858 Bytes
4fb0ce9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useEffect, useState } from "react";

import { LiquidIntro } from "./components/LiquidIntro";
import { LandingPage } from "./components/LandingPage";
import { ChatApp } from "./components/ChatApp";
import { useLLM } from "./hooks/useLLM";
import "katex/dist/katex.min.css";

function App() {
  const { status, loadModel } = useLLM();

  const [stage, setStage] = useState<"intro" | "app">("intro");
  const [hasStarted, setHasStarted] = useState(false);
  const [showChat, setShowChat] = useState(false);

  const isReady = status.state === "ready";
  const isLoading = hasStarted && !isReady && status.state !== "error";

  const handleStart = () => {
    setHasStarted(true);
    loadModel();
  };

  const handleGoHome = () => {
    setShowChat(false);
    setTimeout(() => setHasStarted(false), 700);
  };

  useEffect(() => {
    if (isReady && hasStarted) {
      setShowChat(true);
    }
  }, [isReady, hasStarted]);

  return (
    <div className="relative h-screen w-screen brand-surface">
      {stage === "intro" && (
        <LiquidIntro onEnter={() => setStage("app")} />
      )}

      {stage === "app" && (
        <>
          <div
            className={`absolute inset-0 z-10 transition-all duration-700 ${
              showChat ? "opacity-0 pointer-events-none" : "opacity-100"
            }`}
          >
            <LandingPage
              onStart={handleStart}
              status={status}
              isLoading={isLoading}
              showChat={showChat}
            />
          </div>

          <div
            className={`absolute inset-0 transition-all duration-700 ${
              showChat ? "opacity-100" : "opacity-0 pointer-events-none"
            }`}
          >
            {hasStarted && <ChatApp onGoHome={handleGoHome} />}
          </div>
        </>
      )}
    </div>
  );
}

export default App;