-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLoading.tsx
More file actions
39 lines (36 loc) · 1.22 KB
/
Loading.tsx
File metadata and controls
39 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { useEffect, useState } from "react";
import useStatus from "../hooks/useStatus";
import { RoutinatorStatus } from "../types";
import { API_ENDPOINT } from "../core/contants";
interface LoadingProps {
status: RoutinatorStatus | null;
}
export default function Loading({ status }: LoadingProps) {
useEffect(() => {
if (status && status.error) {
const checkStatus = () => {
setTimeout(() => {
fetch(`${API_ENDPOINT}/api/v1/status`)
.then((r) => r.json())
.then((status) => {
if (status && !status.error) {
window.location.reload();
} else {
checkStatus();
}
}).catch(() => checkStatus());
}, 3000)
};
checkStatus();
}
}, []);
return (
<div id="loading">
<div>
<img src='/src/img/routinator_logo_white.svg' alt='Routinator logo' />
<br />
<p>{status?.error || "Something went wrong"}</p>
</div>
</div>
);
}