Files
Checkmate/client/src/Components/layout/AppLayout.tsx
T

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-02-10 17:53:00 +00:00
import Box from "@mui/material/Box";
2026-02-10 23:53:06 +00:00
import { useState, useEffect, useRef } from "react";
2026-02-20 17:59:08 +00:00
import { useTheme } from "@mui/material/styles";
2026-02-20 18:13:39 +00:00
import { OfflineBanner } from "@/Components/design-elements";
2026-02-10 23:53:06 +00:00
import { setServerUnreachableCallback, get } from "@/Utils/ApiClient";
2026-02-10 17:53:00 +00:00
interface AppLayoutProps {
children: React.ReactNode;
}
const AppLayout = ({ children }: AppLayoutProps) => {
const theme = useTheme();
2026-02-10 23:53:06 +00:00
const [serverUnreachable, setServerUnreachable] = useState(false);
const retryIntervalRef = useRef<number | null>(null);
useEffect(() => {
setServerUnreachableCallback(setServerUnreachable);
}, []);
useEffect(() => {
if (serverUnreachable) {
retryIntervalRef.current = window.setInterval(async () => {
try {
await get("/health", { timeout: 5000 });
} catch {
// NO_OP
}
}, 5000);
} else if (retryIntervalRef.current) {
clearInterval(retryIntervalRef.current);
retryIntervalRef.current = null;
}
return () => {
if (retryIntervalRef.current) {
clearInterval(retryIntervalRef.current);
}
};
}, [serverUnreachable]);
2026-02-10 17:53:00 +00:00
return (
2026-02-10 19:21:57 +00:00
<Box
sx={{
minHeight: "100vh",
2026-02-20 17:59:08 +00:00
backgroundColor: theme.palette.background.default,
2026-02-10 19:21:57 +00:00
}}
>
2026-02-20 17:59:08 +00:00
<OfflineBanner visible={serverUnreachable} />
2026-02-10 19:21:57 +00:00
{children}
</Box>
2026-02-10 17:53:00 +00:00
);
};
export default AppLayout;