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