From 77f5b2db26484b90a1220dacdf9aa95a6eddb23d Mon Sep 17 00:00:00 2001
From: regalijan <r@regalijan.com>
Date: Thu, 19 Oct 2023 16:50:47 -0400
Subject: [PATCH] Maybe this time (yeah right lol)

---
 components/NewGameBan.tsx | 63 +++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 35 deletions(-)

diff --git a/components/NewGameBan.tsx b/components/NewGameBan.tsx
index 39f5cc6..4e8e327 100644
--- a/components/NewGameBan.tsx
+++ b/components/NewGameBan.tsx
@@ -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 } = {
@@ -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>,
-    );
-
     setUsers(newUsers);
-    setRows(newRows);
   }
 
   function removeUser(user: string) {
@@ -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];
   }
@@ -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();
@@ -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 />