diff --git a/src/components/App.tsx b/src/components/App.tsx index 26a42ba..d4e8071 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -7,12 +7,17 @@ import Metrics from './Metrics'; import useStatus, { StatusContext } from '../hooks/useStatus'; import Repositories from './Repositories'; import Connections from './Connections'; +import Loading from './Loading'; export default function App() { const routerState = useRouter(); const { status, roto } = useStatus(); const routeName = routerState.route.name; + if (status && status.error) { + return + } + return ( diff --git a/src/components/Loading.tsx b/src/components/Loading.tsx new file mode 100644 index 0000000..3e7e6f8 --- /dev/null +++ b/src/components/Loading.tsx @@ -0,0 +1,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 ( + + + + + {status?.error || "Something went wrong"} + + + ); +} diff --git a/src/style/index.css b/src/style/index.css index ba4c4ed..9df7fae 100644 --- a/src/style/index.css +++ b/src/style/index.css @@ -12,3 +12,4 @@ @import './prefix-check-sidebar.css'; @import './prefix-check.css'; @import './help.css'; +@import './loading.css'; \ No newline at end of file diff --git a/src/style/loading.css b/src/style/loading.css new file mode 100644 index 0000000..77754d3 --- /dev/null +++ b/src/style/loading.css @@ -0,0 +1,28 @@ +#loading { + width: 100%; + height: 100%; + display: flex; + justify-content: center; + align-items: center; + text-align: center; + min-height: 100vh; + background-color: var(--blue-dark); + background: radial-gradient(circle,rgba(0, 31, 109, 1) 0%, rgba(0, 25, 87, 1) 100%); + color: var(--white); + font-weight: bold; + font-size: 2rem; +} + +#loading img { + max-width: 40rem; +} + +#loading p { + animation: pulsate 2s infinite; +} + +@keyframes pulsate { + from { opacity: 1; } + 50% { opacity: 0; } + to { opacity: 1; } +} \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 3ffddb5..65daf56 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ export interface RoutinatorStatus { + error?: string; version: string; serial: number; now: Date;
{status?.error || "Something went wrong"}