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-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
|
|
|
|
|
|
|
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-06-30 03:37:09 +02:00
|
|
|
{ command: 'Help', online: true },
|
|
|
|
{ command: 'Help', online: true },
|
|
|
|
{ command: 'Help', online: true },
|
|
|
|
{ command: '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>
|
|
|
|
<Controller initialState={command.online} />
|
|
|
|
</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
|