Skip to content

Commit fa1a687

Browse files
authored
Merge pull request #187 from aruznieto/loading-page
feat: loading-page for suspense
2 parents 4a5f846 + 5be9200 commit fa1a687

File tree

6 files changed

+72
-17
lines changed

6 files changed

+72
-17
lines changed

frontend/src/App.jsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "@fontsource/roboto";
22

3+
import { Suspense } from "react";
34
import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom";
45

56
import Theme from "./components/Theme";
@@ -10,19 +11,25 @@ import NotFound from "./routes/NotFound";
1011
import Network from "./routes/Network/Network";
1112
import Settings from "./routes/Settings";
1213

14+
import Loading from "./components/Loading";
15+
16+
import "./i18n";
17+
1318
function App() {
1419
return (
1520
<Theme>
16-
<BrowserRouter basename="/app">
17-
<Bar />
18-
<Switch>
19-
<Route exact path="/" component={Home} />
20-
<Route path="/network/:nwid" component={Network} />
21-
<Route path="/settings" component={Settings} />
22-
<Route path="/404" component={NotFound} />
23-
<Redirect to="/404" />
24-
</Switch>
25-
</BrowserRouter>
21+
<Suspense fallback={<Loading />}>
22+
<BrowserRouter basename="/app">
23+
<Bar />
24+
<Switch>
25+
<Route exact path="/" component={Home} />
26+
<Route path="/network/:nwid" component={Network} />
27+
<Route path="/settings" component={Settings} />
28+
<Route path="/404" component={NotFound} />
29+
<Redirect to="/404" />
30+
</Switch>
31+
</BrowserRouter>
32+
</Suspense>
2633
</Theme>
2734
);
2835
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Typography, Box, CircularProgress } from "@material-ui/core";
2+
3+
import useStyles from "./Loading.styles";
4+
5+
function Loading() {
6+
const classes = useStyles();
7+
8+
return (
9+
<div className={classes.root}>
10+
<CircularProgress color="primary" />
11+
<Typography variant="h6" component="div" className={classes.loadingText}>
12+
Loading
13+
<span className="loadingDots"></span>
14+
</Typography>
15+
</div>
16+
);
17+
}
18+
19+
export default Loading;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Loading.styles.jsx
2+
import { makeStyles } from "@material-ui/core/styles";
3+
4+
const useStyles = makeStyles({
5+
root: {
6+
display: "flex",
7+
flexDirection: "column",
8+
justifyContent: "center",
9+
alignItems: "center",
10+
height: "100vh",
11+
},
12+
loadingText: {
13+
marginTop: "16px",
14+
position: "relative",
15+
"& .loadingDots::after": {
16+
content: '"."',
17+
position: "absolute",
18+
left: "100%",
19+
marginLeft: "4px",
20+
animation: "$loadingDots 1s infinite",
21+
},
22+
},
23+
"@keyframes loadingDots": {
24+
"0%": { content: '"."' },
25+
"25%": { content: '".."' },
26+
"50%": { content: '"..."' },
27+
"75%": { content: '"...."' },
28+
"100%": { content: '"."' },
29+
},
30+
});
31+
32+
export default useStyles;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./Loading.jsx";

frontend/src/components/NetworkRules/NetworkRules.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import debounce from "lodash/debounce";
1717
import { useState } from "react";
1818
import API from "utils/API";
1919

20-
import { useTranslation, Trans } from "react-i18next";
20+
import { useTranslation } from "react-i18next";
2121

2222
function NetworkRules({ network, callback }) {
2323
const { t, i18n } = useTranslation();

frontend/src/index.jsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import "./index.css";
22

3-
import React, { Suspense } from "react";
3+
import React from "react";
44
import ReactDOM from "react-dom";
55

66
import App from "./App";
77

8-
import "./i18n";
9-
108
ReactDOM.render(
119
<React.StrictMode>
12-
<Suspense fallback={<div>Loading...</div>}>
13-
<App />
14-
</Suspense>
10+
<App />
1511
</React.StrictMode>,
1612
document.getElementById("root")
1713
);

0 commit comments

Comments
 (0)