many changes
This commit is contained in:
@@ -4,9 +4,10 @@ import React, { useEffect, useState, useRef } from "react";
|
|||||||
import Stats from "./stats";
|
import Stats from "./stats";
|
||||||
import ServerName from "./serverName";
|
import ServerName from "./serverName";
|
||||||
import ServerControl from "./serverControl";
|
import ServerControl from "./serverControl";
|
||||||
import ServerRunning from "./serverStatus";
|
import ServerStatus from "./serverStatus";
|
||||||
|
|
||||||
const Console = () => {
|
const Console = () => {
|
||||||
|
const [apiKey, setApiKey] = useState("");
|
||||||
const [url, setUrl] = useState("");
|
const [url, setUrl] = useState("");
|
||||||
const [token, setToken] = useState("");
|
const [token, setToken] = useState("");
|
||||||
const [output, setOutput] = useState<string[]>([]);
|
const [output, setOutput] = useState<string[]>([]);
|
||||||
@@ -23,15 +24,18 @@ const Console = () => {
|
|||||||
const websocketRef = useRef<WebSocket | null>(null); // Dodajemy ref do WebSocket
|
const websocketRef = useRef<WebSocket | null>(null); // Dodajemy ref do WebSocket
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null); // Dodajemy referencję do textarea
|
const textareaRef = useRef<HTMLTextAreaElement>(null); // Dodajemy referencję do textarea
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async (apiKey: string) => {
|
||||||
|
setApiKey("ptlc_aDGU4VHNQuN5t6dyxNzVon3UZLR5ehuySmdR7xsUbMm");
|
||||||
|
|
||||||
|
console.log("Fetching data...");
|
||||||
|
console.log(apiKey);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"https://ptero.przeqpiciel.com/api/client/servers/0bf192ab/websocket",
|
"https://ptero.przeqpiciel.com/api/client/servers/0bf192ab/websocket",
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization:
|
Authorization: "Bearer " + apiKey.toString(),
|
||||||
"Bearer ptlc_aDGU4VHNQuN5t6dyxNzVon3UZLR5ehuySmdR7xsUbMm",
|
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -52,9 +56,9 @@ const Console = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData();
|
fetchData(apiKey);
|
||||||
fetchStats();
|
fetchStats();
|
||||||
}, []);
|
}, [apiKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (url && token) {
|
if (url && token) {
|
||||||
@@ -72,7 +76,7 @@ const Console = () => {
|
|||||||
|
|
||||||
switch (message.event) {
|
switch (message.event) {
|
||||||
case "token expiring":
|
case "token expiring":
|
||||||
fetchData();
|
fetchData(apiKey);
|
||||||
websocket.send(`{"event":"auth","args":["${token}"]}`);
|
websocket.send(`{"event":"auth","args":["${token}"]}`);
|
||||||
console.log("New token fetched");
|
console.log("New token fetched");
|
||||||
break;
|
break;
|
||||||
@@ -152,7 +156,7 @@ const Console = () => {
|
|||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<div className="w-4/5 flex justify-self-auto justify-between items-center">
|
<div className="w-4/5 flex justify-self-auto justify-between items-center">
|
||||||
<ServerName serverName="asdf " />
|
<ServerName serverName="asdf " />
|
||||||
<ServerRunning serverStatus={serverStatus} />
|
<ServerStatus serverStatus={serverStatus} />
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/5 flex justify-between">
|
<div className="w-1/5 flex justify-between">
|
||||||
<ServerControl websocketRef={websocketRef} />
|
<ServerControl websocketRef={websocketRef} />
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ interface Props {
|
|||||||
const serverName = ({ serverName }: Props) => {
|
const serverName = ({ serverName }: Props) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>{serverName}</div>
|
<div>
|
||||||
|
Server name: <strong>{serverName}</strong>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,30 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const serverStatus = ({ serverStatus }: Props) => {
|
const serverStatus = ({ serverStatus }: Props) => {
|
||||||
let bgColor = "bg-success";
|
let color = "bg-danger";
|
||||||
|
switch (serverStatus) {
|
||||||
|
case "running":
|
||||||
|
serverStatus = "Running";
|
||||||
|
color = "bg-success";
|
||||||
|
break;
|
||||||
|
case "offline":
|
||||||
|
serverStatus = "Offline";
|
||||||
|
color = "bg-error";
|
||||||
|
break;
|
||||||
|
case "starting":
|
||||||
|
serverStatus = "Starting";
|
||||||
|
color = "bg-info";
|
||||||
|
break;
|
||||||
|
case "stopping":
|
||||||
|
serverStatus = "Stopping";
|
||||||
|
color = "bg-error";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
serverStatus = "N/A";
|
||||||
|
}
|
||||||
|
|
||||||
|
let bgColor =
|
||||||
|
"p-3 rounded-md w-32 font-weight-600 font-face text-center " + color;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user