diff --git a/webui/src/states/Root/pages/Overview/components/Server/components/ServerInfo/ServerInfo.jsx b/webui/src/states/Root/pages/Overview/components/Server/components/ServerInfo/ServerInfo.jsx new file mode 100644 index 0000000..9542097 --- /dev/null +++ b/webui/src/states/Root/pages/Overview/components/Server/components/ServerInfo/ServerInfo.jsx @@ -0,0 +1,59 @@ +import {Button, Stack, Typography} from "@mui/material"; +import {t} from "i18next"; +import {AvTimer, Bolt, Group, PowerOff, Share} from "@mui/icons-material"; +import {useEffect} from "react"; +import {proxyRequest} from "@/common/utils/RequestUtil.js"; + +export const ServerInfo = ({status, uuid, serverInfo, setServerInfo, setAlert}) => { + + const updateServerInfo = () => { + proxyRequest(uuid + "/api/stats/") + .then((response) => { + if (response.status === 200) return response.json(); + throw new Error("Server is offline"); + }) + .then((data) => setServerInfo(data)) + .catch(() => setServerInfo(null)); + } + + useEffect(() => { + updateServerInfo(); + + const interval = setInterval(() => updateServerInfo(), 5000); + + return () => clearInterval(interval); + }, []); + + + return ( + + {status === "ONLINE" && serverInfo === null && ( + )} + {status === "ONLINE" && serverInfo !== null && Object.keys(serverInfo).length === 0 && ( + )} + {status === "ONLINE" && serverInfo !== null && Object.keys(serverInfo).length > 0 && ( + + + + {serverInfo.online_players} / {serverInfo.max_players} + + + + {serverInfo.tps} + + + + + + )} + + ) +} \ No newline at end of file