Merge pull request #187 from aruznieto/loading-page

feat: loading-page for suspense
This commit is contained in:
Aliaksei 2023-10-20 18:05:39 +01:00 committed by GitHub
commit fa1a687147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 17 deletions

View file

@ -1,5 +1,6 @@
import "@fontsource/roboto"; import "@fontsource/roboto";
import { Suspense } from "react";
import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom"; import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom";
import Theme from "./components/Theme"; import Theme from "./components/Theme";
@ -10,19 +11,25 @@ import NotFound from "./routes/NotFound";
import Network from "./routes/Network/Network"; import Network from "./routes/Network/Network";
import Settings from "./routes/Settings"; import Settings from "./routes/Settings";
import Loading from "./components/Loading";
import "./i18n";
function App() { function App() {
return ( return (
<Theme> <Theme>
<BrowserRouter basename="/app"> <Suspense fallback={<Loading />}>
<Bar /> <BrowserRouter basename="/app">
<Switch> <Bar />
<Route exact path="/" component={Home} /> <Switch>
<Route path="/network/:nwid" component={Network} /> <Route exact path="/" component={Home} />
<Route path="/settings" component={Settings} /> <Route path="/network/:nwid" component={Network} />
<Route path="/404" component={NotFound} /> <Route path="/settings" component={Settings} />
<Redirect to="/404" /> <Route path="/404" component={NotFound} />
</Switch> <Redirect to="/404" />
</BrowserRouter> </Switch>
</BrowserRouter>
</Suspense>
</Theme> </Theme>
); );
} }

View file

@ -0,0 +1,19 @@
import { Typography, Box, CircularProgress } from "@material-ui/core";
import useStyles from "./Loading.styles";
function Loading() {
const classes = useStyles();
return (
<div className={classes.root}>
<CircularProgress color="primary" />
<Typography variant="h6" component="div" className={classes.loadingText}>
Loading
<span className="loadingDots"></span>
</Typography>
</div>
);
}
export default Loading;

View file

@ -0,0 +1,32 @@
// Loading.styles.jsx
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles({
root: {
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
height: "100vh",
},
loadingText: {
marginTop: "16px",
position: "relative",
"& .loadingDots::after": {
content: '"."',
position: "absolute",
left: "100%",
marginLeft: "4px",
animation: "$loadingDots 1s infinite",
},
},
"@keyframes loadingDots": {
"0%": { content: '"."' },
"25%": { content: '".."' },
"50%": { content: '"..."' },
"75%": { content: '"...."' },
"100%": { content: '"."' },
},
});
export default useStyles;

View file

@ -0,0 +1 @@
export { default } from "./Loading.jsx";

View file

@ -17,7 +17,7 @@ import debounce from "lodash/debounce";
import { useState } from "react"; import { useState } from "react";
import API from "utils/API"; import API from "utils/API";
import { useTranslation, Trans } from "react-i18next"; import { useTranslation } from "react-i18next";
function NetworkRules({ network, callback }) { function NetworkRules({ network, callback }) {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();

View file

@ -1,17 +1,13 @@
import "./index.css"; import "./index.css";
import React, { Suspense } from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import App from "./App"; import App from "./App";
import "./i18n";
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<Suspense fallback={<div>Loading...</div>}> <App />
<App />
</Suspense>
</React.StrictMode>, </React.StrictMode>,
document.getElementById("root") document.getElementById("root")
); );