From 1a8b7af2af5944b3825a52b3cbbc4e1a1dd18482 Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:50:16 +0300 Subject: [PATCH] Implement Lazy loading --- Plan/react/dashboard/src/App.js | 103 +++++++++++++++++--------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/Plan/react/dashboard/src/App.js b/Plan/react/dashboard/src/App.js index f1fd65460..054f589cb 100644 --- a/Plan/react/dashboard/src/App.js +++ b/Plan/react/dashboard/src/App.js @@ -4,12 +4,6 @@ import './style/style.css'; import {BrowserRouter, Navigate, Route, Routes} from "react-router-dom"; import React from "react"; -import PlayerPage from "./views/layout/PlayerPage"; -import PlayerOverview from "./views/player/PlayerOverview"; -import PlayerSessions from "./views/player/PlayerSessions"; -import PlayerPvpPve from "./views/player/PlayerPvpPve"; -import PlayerServers from "./views/player/PlayerServers"; -import PlayerPluginData from "./views/player/PlayerPluginData"; import {ThemeContextProvider} from "./hooks/themeHook"; import axios from "axios"; import ErrorView from "./views/ErrorView"; @@ -17,23 +11,32 @@ import {faMapSigns} from "@fortawesome/free-solid-svg-icons"; import {MetadataContextProvider} from "./hooks/metadataHook"; import {AuthenticationContextProvider} from "./hooks/authenticationHook"; import {NavigationContextProvider} from "./hooks/navigationHook"; -import ServerPage from "./views/layout/ServerPage"; -import ServerOverview from "./views/server/ServerOverview"; import MainPageRedirect from "./components/navigation/MainPageRedirect"; -import OnlineActivity from "./views/server/OnlineActivity"; -import ServerSessions from "./views/server/ServerSessions"; -import ServerPvpPve from "./views/server/ServerPvpPve"; -import PlayerbaseOverview from "./views/server/PlayerbaseOverview"; -import ServerPlayers from "./views/server/ServerPlayers"; -import PlayersPage from "./views/layout/PlayersPage"; -import AllPlayers from "./views/players/AllPlayers"; -import ServerGeolocations from "./views/server/ServerGeolocations"; -import LoginPage from "./views/layout/LoginPage"; -import ServerPerformance from "./views/server/ServerPerformance"; -import ServerPluginData from "./views/server/ServerPluginData"; -import ServerWidePluginData from "./views/server/ServerWidePluginData"; -import ErrorsPage from "./views/layout/ErrorsPage"; +const PlayerPage = React.lazy(() => import("./views/layout/PlayerPage")); +const PlayerOverview = React.lazy(() => import("./views/player/PlayerOverview")); +const PlayerSessions = React.lazy(() => import("./views/player/PlayerSessions")); +const PlayerPvpPve = React.lazy(() => import("./views/player/PlayerPvpPve")); +const PlayerServers = React.lazy(() => import("./views/player/PlayerServers")); +const PlayerPluginData = React.lazy(() => import("./views/player/PlayerPluginData")); + +const ServerPage = React.lazy(() => import("./views/layout/ServerPage")); +const ServerOverview = React.lazy(() => import("./views/server/ServerOverview")); +const OnlineActivity = React.lazy(() => import("./views/server/OnlineActivity")); +const ServerSessions = React.lazy(() => import("./views/server/ServerSessions")); +const ServerPvpPve = React.lazy(() => import("./views/server/ServerPvpPve")); +const PlayerbaseOverview = React.lazy(() => import("./views/server/PlayerbaseOverview")); +const ServerPlayers = React.lazy(() => import("./views/server/ServerPlayers")); +const ServerGeolocations = React.lazy(() => import("./views/server/ServerGeolocations")); +const LoginPage = React.lazy(() => import("./views/layout/LoginPage")); +const ServerPerformance = React.lazy(() => import("./views/server/ServerPerformance")); +const ServerPluginData = React.lazy(() => import("./views/server/ServerPluginData")); +const ServerWidePluginData = React.lazy(() => import("./views/server/ServerWidePluginData")); + +const PlayersPage = React.lazy(() => import("./views/layout/PlayersPage")); +const AllPlayers = React.lazy(() => import("./views/players/AllPlayers")); + +const ErrorsPage = React.lazy(() => import("./views/layout/ErrorsPage")); const SwaggerView = React.lazy(() => import("./views/SwaggerView")); const OverviewRedirect = () => { @@ -52,6 +55,12 @@ const ContextProviders = ({children}) => ( ) +const Lazy = ({children}) => ( + }> + {children} + +) + function App() { axios.defaults.withCredentials = true; @@ -63,47 +72,45 @@ function App() { }/> }/> - }/> - }> - }/> - }/> - }/> - }/> - }/> - }/> + }/> + }> + }/> + }/> + }/> + }/> + }/> + }/> }/> - }> - }/> - }/> + }> + }/> + }/> - }> - }/> - }/> - }/> - }/> - }/> - }/> + }> + }/> + }/> + }/> + }/> + }/> + }/> }/> - }/> - }/> - }/> - }/> - }/> + }/> + }/> + }/> + }/> + }/> }/> - }/> - }> - - }/> + }/> + }/>