|
1 | | -import './App.css'; |
| 1 | +import "./App.css"; |
| 2 | +import { lazy, Suspense } from "react"; |
2 | 3 | import { BrowserRouter, Route, Routes } from "react-router-dom"; |
3 | | -import Navbar from "./components/Navbar"; |
4 | | -import Home from "./pages/Home"; |
5 | | -import Search from './pages/Search'; |
6 | | -import { DataProvider } from './context/DataContext'; |
7 | | -import ImageTree from './pages/3DTree'; |
8 | | -import React, { useEffect, useState } from 'react'; |
9 | | -import axios from 'axios'; |
10 | | -import { ToastContainer, toast } from 'react-toastify'; |
11 | | -import 'react-toastify/dist/ReactToastify.css'; |
| 4 | +import { DataProvider } from "./context/DataContext"; |
| 5 | +import React, { useEffect, useState } from "react"; |
| 6 | +import axios from "axios"; |
| 7 | +import { ToastContainer, toast } from "react-toastify"; |
| 8 | +import "react-toastify/dist/ReactToastify.css"; |
| 9 | + |
| 10 | +// Add delay wrapper for lazy loading |
| 11 | +const delayLoad = (promise) => { |
| 12 | + return new Promise(resolve => { |
| 13 | + setTimeout(() => { |
| 14 | + resolve(promise); |
| 15 | + }, 2000); |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +// Modify lazy imports to include delay |
| 20 | +const Navbar = lazy(() => delayLoad(import("./components/Navbar"))); |
| 21 | +const Home = lazy(() => delayLoad(import("./pages/Home"))); |
| 22 | +const Search = lazy(() => delayLoad(import("./pages/Search"))); |
| 23 | +const ImageTree = lazy(() => delayLoad(import("./pages/3DTree.jsx"))); |
12 | 24 |
|
13 | 25 | function App() { |
14 | 26 | const [data, setData] = useState([]); |
15 | | - const [error,seterror]=useState(false) |
16 | | - useEffect(() => { |
| 27 | + const [error, seterror] = useState(false); |
| 28 | + |
| 29 | + useEffect(() => { |
17 | 30 | const fetchData = async () => { |
18 | 31 | try { |
19 | | - const response = await axios.get(`https://devluplabs.iitj.ac.in/ftadmin/tree/`); |
| 32 | + const response = await axios.get( |
| 33 | + `https://devluplabs.iitj.ac.in/ftadmin/tree/` |
| 34 | + ); |
20 | 35 | setData(response.data); |
21 | 36 | } catch (error) { |
22 | | - seterror(true) |
| 37 | + seterror(true); |
23 | 38 | } |
24 | 39 | }; |
25 | 40 | fetchData(); |
26 | 41 | }, []); |
27 | 42 |
|
28 | | - if(error){ |
29 | | - toast.error("server error",{ |
30 | | - autoClose:20000 |
31 | | - }) |
| 43 | + if (error) { |
| 44 | + toast.error("server error", { |
| 45 | + autoClose: 20000, |
| 46 | + }); |
32 | 47 | } |
33 | | -// console.log(window.location.pathname) |
| 48 | + |
34 | 49 | return ( |
35 | | - |
36 | | - <BrowserRouter |
37 | | - basename="/familytree/" |
38 | | - > |
39 | | - <DataProvider> |
40 | | - <ToastContainer /> |
41 | | - <Navbar error={error}/> |
42 | | - <Routes> |
43 | | - <Route path="/" element={<Home data={data}/>} /> |
44 | | - <Route path="/search/:id" element={<Search />} /> |
45 | | - <Route path="/ImageTree" element={<ImageTree data={data}/>} /> |
46 | | - </Routes> |
47 | | - </DataProvider> |
48 | | - </BrowserRouter> |
| 50 | + <BrowserRouter basename="/familytree/"> |
| 51 | + <Suspense fallback={<div className="w-full h-[100vh] text-4xl flex justify-center items-center">Loading...</div>}> |
| 52 | + <DataProvider> |
| 53 | + <ToastContainer /> |
| 54 | + <Navbar error={error} /> |
| 55 | + <Routes> |
| 56 | + <Route path="/" element={<Home data={data} />} /> |
| 57 | + <Route path="/search/:id" element={<Search />} /> |
| 58 | + <Route path="/ImageTree" element={<ImageTree data={data} />} /> |
| 59 | + </Routes> |
| 60 | + </DataProvider> |
| 61 | + </Suspense> |
| 62 | + </BrowserRouter> |
49 | 63 | ); |
50 | 64 | } |
51 | 65 |
|
|
0 commit comments