diff --git a/webui/src/states/Root/pages/Overview/components/Server/Server.jsx b/webui/src/states/Root/pages/Overview/components/Server/Server.jsx index aa66a5d..3aae87f 100644 --- a/webui/src/states/Root/pages/Overview/components/Server/Server.jsx +++ b/webui/src/states/Root/pages/Overview/components/Server/Server.jsx @@ -1,16 +1,18 @@ -import {Avatar, Box, Button, Chip, CircularProgress, IconButton, Stack, Tooltip, Typography} from "@mui/material"; -import {AvTimer, Bolt, Dns, Group, PowerOff, PowerSettingsNew, Share} from "@mui/icons-material"; +import {Alert, Avatar, Box, Chip, CircularProgress, IconButton, Snackbar, Stack, Typography} from "@mui/material"; +import {Dns, MoreVert} from "@mui/icons-material"; import PurpurImage from "@/common/assets/software/purpur.webp"; import PaperImage from "@/common/assets/software/paper.webp"; import SpigotImage from "@/common/assets/software/spigot.webp"; -import {useContext, useEffect, useRef, useState} from "react"; -import {isDev, postRequest, PROXY_URL, proxyRequest} from "@/common/utils/RequestUtil.js"; -import {ServerContext} from "@/common/contexts/Server/index.js"; -import {t} from "i18next"; +import {useEffect, useRef, useState} from "react"; +import {isDev, PROXY_URL} from "@/common/utils/RequestUtil.js"; +import ServerInfo from "@/states/Root/pages/Overview/components/Server/components/ServerInfo"; +import ServerMenu from "@/states/Root/pages/Overview/components/Server/components/ServerMenu"; export const Server = ({uuid, configuration, status}) => { + const [menuOpen, setMenuOpen] = useState(false); + const menuRef = useRef(null); - const {updateServer} = useContext(ServerContext); + const [alert, setAlert] = useState(null); const frameRef = useRef(null); const serverRef = useRef(null); @@ -23,8 +25,7 @@ export const Server = ({uuid, configuration, status}) => { }, [frameOpen]); useEffect(() => { - if (isDev) return () => { - }; + if (isDev) return () => {}; const interval = setInterval(() => { if (frameRef.current) { @@ -46,26 +47,6 @@ export const Server = ({uuid, configuration, status}) => { if (serverInfo === null || Object.keys(serverInfo).length === 0) setFrameOpen(false); }, [serverInfo]); - 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)); - } - - const startServer = async () => { - await postRequest("server/start", {uuid}); - updateServer(); - } - - const stopServer = async () => { - await postRequest("server/stop", {uuid}); - updateServer(); - } - const onServerClick = () => { if (serverRef.current === null) return; if (serverRef.current.contains(document.activeElement)) return; @@ -75,91 +56,60 @@ export const Server = ({uuid, configuration, status}) => { } } - useEffect(() => { - updateServerInfo(); - - const interval = setInterval(() => updateServerInfo(), 5000); - - return () => clearInterval(interval); - }, []); - return ( - 0 ? "pointer" : "default"}} - boxShadow={5} gap={2} ref={serverRef} onClick={onServerClick}> + <> + setAlert(null)} + anchorOrigin={{vertical: "bottom", horizontal: "right"}}> + {alert !== null ? alert.message : ""} + + + 0 ? "pointer" : "default"}} + boxShadow={5} gap={2} ref={serverRef} onClick={onServerClick}> - - - - - - - - {configuration.type} - {configuration.name} - + + + + + + + + {configuration.type} + {configuration.name} + + + + {configuration.description} - {configuration.description} + - - {serverInfo === null && ( - )} - {serverInfo !== null && Object.keys(serverInfo).length === 0 && ( - )} - {serverInfo !== null && Object.keys(serverInfo).length > 0 && ( - - - - {serverInfo.online_players} / {serverInfo.max_players} - - - - {serverInfo.tps} - - - - - - )} - - - - - - status === "OFFLINE" ? startServer() : stopServer()}> - + setMenuOpen(!menuOpen)} + ref={menuRef}> + - - + + - - {frameOpen && !frameLoaded && ( - - - - )} + {frameOpen && !frameLoaded && ( + + + + )} - {frameOpen && ( -