Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Maybe this time (yeah right lol)
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent e2cafd6 commit 77f5b2d
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions components/NewGameBan.tsx
Expand Up @@ -22,11 +22,10 @@ import {
VStack,
useToast,
} from "@chakra-ui/react";
import { type ReactElement, useState } from "react";
import { useState } from "react";

export default function (props: { isOpen: boolean; onClose: () => void }) {
const actionMap: { [k: string]: number } = {};
const [rows, setRows] = useState([] as ReactElement[]);
const [users, setUsers] = useState([] as string[]);
const toast = useToast();
const fileTypes: { [k: string]: string } = {
Expand All @@ -48,35 +47,9 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {

function addUser(user: string) {
const newUsers = [...users];
newUsers.push(user);

const newRows = [...rows];
newRows.push(
<Tr key={user}>
<Td>{user}</Td>
<Td>
<RadioGroup
onChange={(val) =>
Object.defineProperty(actionMap, user, {
value: parseInt(val),
})
}
>
<VStack>
<Radio value="0">Do Nothing</Radio>
<Radio value="1">Hide from Leaderboards</Radio>
<Radio value="2">Ban</Radio>
</VStack>
</RadioGroup>
</Td>
<Td>
<Link onClick={() => removeUser(user)}>Remove</Link>
</Td>
</Tr>,
);

newUsers.push(user);
setUsers(newUsers);
setRows(newRows);
}

function removeUser(user: string) {
Expand All @@ -85,12 +58,8 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {

if (userIdx === -1) return;

const newRows = [...rows];

newUsers.splice(userIdx, 1);
newRows.splice(userIdx, 1);
setUsers(newUsers);
setRows(newRows);

delete actionMap[user];
}
Expand All @@ -99,7 +68,7 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
(document.getElementById("username") as HTMLInputElement).value = "";
(document.getElementById("evidence") as HTMLInputElement).value = "";

setRows([]);
setUsers([]);
Object.keys(actionMap).forEach((k) => delete actionMap[k]);

props.onClose();
Expand Down Expand Up @@ -243,7 +212,31 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
<Th>Remove</Th>
</Tr>
</Thead>
<Tbody>{rows}</Tbody>
<Tbody>
{users.map((user) => (
<Tr key={user}>
<Td>{user}</Td>
<Td>
<RadioGroup
onChange={(val) =>
Object.defineProperty(actionMap, user, {
value: parseInt(val),
})
}
>
<VStack>
<Radio value="0">Do Nothing</Radio>
<Radio value="1">Hide from Leaderboards</Radio>
<Radio value="2">Ban</Radio>
</VStack>
</RadioGroup>
</Td>
<Td>
<Link onClick={() => removeUser(user)}>Remove</Link>
</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
<br />
Expand Down

0 comments on commit 77f5b2d

Please sign in to comment.