home.tsx 2.2 KB
Newer Older
dechen lin's avatar
dechen lin committed
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
"use client";

import ErrorBoundary from "@/components/error-boundary";
import styles from "./home.module.scss";
import { SlotID, Path } from "@/constant/route";
import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";
import { ExtractorSide } from "./extract-side";
import { LanguageProvider } from "@/context/language-provider";
import PDFUpload from "@/pages/extract/components/pdf-upload";
import PDFExtractionJob from "@/pages/extract/components/pdf-extraction";

// judge if the app has hydrated
// const useHasHydrated = () => {
//   const [hasHydrated, setHasHydrated] = useState<boolean>(false);
//   useEffect(() => {
//     setHasHydrated(true);
//   }, []);
//   return hasHydrated;
// };

export function WindowContent() {
  const isHome = location.pathname === Path.Home;
  return (
    <>
      <ExtractorSide className={isHome ? styles["sidebar-show"] : ""} />
      <div className="flex-1">
        <Outlet />
      </div>
    </>
  );
}

function Screen() {
  // if you do not need to use the renderContent for rendering router, you can use the other render function to interrupt before the renderContent

  const renderContent = () => {
    return (
      <div className="w-full h-full flex" id={SlotID.AppBody}>
        <Routes>
          <Route path="/" element={<WindowContent />}>
            <Route
              path="/OpenSourceTools/Extractor/PDF"
              element={<PDFUpload />}
            />
            <Route
              path="/OpenSourceTools/Extractor/PDF/:jobID"
              element={<PDFExtractionJob />}
            />
            {/* <Route path="*" element={<PDFUpload />} /> */}
          </Route>
        </Routes>
      </div>

      // <ExtractorSide className={isHome ? styles["sidebar-show"] : ""} />
      // <WindowContent className="flex-1">
      //   <AppRoutes />
      // </WindowContent>
    );
  };

  return <>{renderContent()}</>;
}

export function Home() {
  // leave this comment to check if the app has hydrated
  // if (!useHasHydrated()) {
  //   return <LoadingAnimation />;
  // }

  return (
    <ErrorBoundary>
      <LanguageProvider>
        <BrowserRouter>
          <Screen />
        </BrowserRouter>
      </LanguageProvider>
    </ErrorBoundary>
  );
}