2021-11-16 22:52:23 +01:00
|
|
|
import React from "react";
|
2021-06-28 11:36:41 +02:00
|
|
|
import {
|
2021-11-16 22:52:23 +01:00
|
|
|
Table,
|
|
|
|
Thead,
|
|
|
|
Tbody,
|
|
|
|
Tr,
|
|
|
|
Th,
|
|
|
|
Td,
|
|
|
|
TableCaption,
|
|
|
|
Switch,
|
|
|
|
Text,
|
|
|
|
} from "@chakra-ui/react";
|
|
|
|
import Head from "next/head";
|
|
|
|
import { useSession } from "next-auth/client";
|
|
|
|
import axios from "axios";
|
|
|
|
import { FaBullseye } from "react-icons/fa";
|
2021-06-25 02:07:36 +02:00
|
|
|
|
2021-06-30 03:37:09 +02:00
|
|
|
function Controller({ initialState }) {
|
2021-11-16 22:52:23 +01:00
|
|
|
const [online, setOnline] = React.useState(initialState);
|
2021-06-28 11:36:41 +02:00
|
|
|
|
2021-11-16 22:52:23 +01:00
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
size="lg"
|
|
|
|
colorScheme={"teal"}
|
|
|
|
isChecked={online}
|
|
|
|
value={online}
|
|
|
|
onChange={() => {
|
|
|
|
setOnline(!online);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2021-06-28 11:36:41 +02:00
|
|
|
}
|
2021-06-25 02:07:36 +02:00
|
|
|
|
2021-07-04 12:42:43 +02:00
|
|
|
function processOnline(status) {
|
2021-11-16 22:52:23 +01:00
|
|
|
console.log(status);
|
2022-01-08 22:38:17 +01:00
|
|
|
if (status == "online") return true;
|
|
|
|
if (status == "offline") return false;
|
|
|
|
if (status == "maintenance") return false;
|
2021-07-04 12:42:43 +02:00
|
|
|
}
|
|
|
|
|
2021-06-25 02:07:36 +02:00
|
|
|
function Commands() {
|
2021-11-16 22:52:23 +01:00
|
|
|
const [session, loading] = useSession();
|
2021-06-28 11:36:41 +02:00
|
|
|
|
2021-11-16 22:52:23 +01:00
|
|
|
const [categories, setCategories] = React.useState([
|
|
|
|
{ name: "Help", commands: [{ name: "Help", online: true }] },
|
|
|
|
]);
|
2021-06-29 08:41:32 +02:00
|
|
|
|
2021-11-16 22:52:23 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
axios
|
|
|
|
.get("https://api.cath.gq/api/v1/client/commands")
|
|
|
|
.then(res => setCategories(res.data));
|
|
|
|
}, []);
|
2021-06-25 02:07:36 +02:00
|
|
|
|
2021-11-16 22:52:23 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{session && (
|
2021-06-25 02:07:36 +02:00
|
|
|
<>
|
2021-11-16 22:52:23 +01:00
|
|
|
<Head>
|
|
|
|
<title>Cath Commands</title>
|
|
|
|
</Head>
|
|
|
|
<Table variant="simple">
|
|
|
|
<TableCaption>Command Controls</TableCaption>
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>Command</Th>
|
|
|
|
<Th>Enabled</Th>
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
|
|
{categories.map((category, idx) => (
|
2021-06-30 03:37:09 +02:00
|
|
|
<>
|
2021-11-16 22:52:23 +01:00
|
|
|
<Text fontSize="3xl">{category.name}</Text>
|
|
|
|
{category.commands.map((command, commandIdx) => (
|
|
|
|
<Tr key={commandIdx}>
|
|
|
|
<Td>{command.name}</Td>
|
|
|
|
<Td>
|
|
|
|
<Controller
|
|
|
|
initialState={processOnline(command.status)}
|
|
|
|
/>
|
|
|
|
</Td>
|
|
|
|
</Tr>
|
|
|
|
))}
|
2021-06-30 03:37:09 +02:00
|
|
|
</>
|
2021-11-16 22:52:23 +01:00
|
|
|
))}
|
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
</>
|
|
|
|
)}{" "}
|
|
|
|
{!session && (
|
|
|
|
<>
|
|
|
|
<h1>Seems like you're not logged in. Log in to get started!</h1>
|
2021-06-25 02:07:36 +02:00
|
|
|
</>
|
2021-11-16 22:52:23 +01:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
2021-06-25 02:07:36 +02:00
|
|
|
}
|
|
|
|
|
2021-11-16 22:52:23 +01:00
|
|
|
export default Commands;
|