Skip to content

Commit d4b0a01

Browse files
committed
Reload page when loaded
1 parent 0336cc7 commit d4b0a01

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/components/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export default function App() {
1414
const { status, roto } = useStatus();
1515
const routeName = routerState.route.name;
1616

17-
if (!status || (status && status.error)) {
18-
return <Loading error={status?.error} />
17+
if (status && status.error) {
18+
return <Loading status={status} />
1919
}
2020

2121
return (

src/components/Loading.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1+
import { useEffect, useState } from "react";
2+
import useStatus from "../hooks/useStatus";
3+
import { RoutinatorStatus } from "../types";
4+
import { API_ENDPOINT } from "../core/contants";
5+
16
interface LoadingProps {
2-
error?: string;
7+
status: RoutinatorStatus | null;
38
}
49

5-
export default function Loading({ error }: LoadingProps) {
10+
export default function Loading({ status }: LoadingProps) {
11+
useEffect(() => {
12+
if (status && status.error) {
13+
const checkStatus = () => {
14+
setTimeout(() => {
15+
fetch(`${API_ENDPOINT}/api/v1/status`)
16+
.then((r) => r.json())
17+
.then((status) => {
18+
if (status && !status.error) {
19+
window.location.reload();
20+
} else {
21+
checkStatus();
22+
}
23+
}).catch(() => checkStatus());
24+
}, 3000)
25+
};
26+
checkStatus();
27+
}
28+
}, []);
29+
630
return (
731
<div id="loading">
832
<div>
933
<img src='/src/img/routinator_logo_white.svg' alt='Routinator logo' />
1034
<br />
11-
<p>{error || "Something went wrong"}</p>
35+
<p>{status?.error || "Something went wrong"}</p>
1236
</div>
1337
</div>
1438
);

src/style/loading.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@
1515

1616
#loading img {
1717
max-width: 40rem;
18-
animation: pulse 2s infinite;
1918
}

0 commit comments

Comments
 (0)