nyx-dashboard/pages/controlpanel/commands.js

99 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2021-11-16 22:52:23 +01:00
import React from "react";
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";
function Controller({ initialState }) {
2021-11-16 22:52:23 +01:00
const [online, setOnline] = React.useState(initialState);
2021-11-16 22:52:23 +01:00
return (
<Switch
size="lg"
colorScheme={"teal"}
isChecked={online}
value={online}
onChange={() => {
setOnline(!online);
}}
/>
);
}
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;
}
function Commands() {
2021-11-16 22:52:23 +01:00
const [session, loading] = useSession();
2021-11-16 22:52:23 +01:00
const [categories, setCategories] = React.useState([
{ name: "Help", commands: [{ name: "Help", online: true }] },
]);
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-11-16 22:52:23 +01:00
return (
<>
{session && (
<>
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-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-11-16 22:52:23 +01:00
))}
</Tbody>
</Table>
</>
)}{" "}
{!session && (
<>
<h1>Seems like you&apos;re not logged in. Log in to get started!</h1>
</>
2021-11-16 22:52:23 +01:00
)}
</>
);
}
2021-11-16 22:52:23 +01:00
export default Commands;