Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Another attempt to fix removing users on game ban modal
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 2964beb commit e2cafd6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions components/NewGameBan.tsx
Expand Up @@ -27,6 +27,7 @@ import { type ReactElement, 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 } = {
gif: "image/gif",
Expand All @@ -46,6 +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}>
Expand All @@ -71,20 +75,21 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
</Tr>,
);

setUsers(newUsers);
setRows(newRows);
}

function removeUser(user: string) {
const newRows = [...rows];
const el = newRows.find((el) => el.key === user);
const newUsers = [...users];
const userIdx = newUsers.indexOf(user);

if (!el) return;
if (userIdx === -1) return;

const elIdx = newRows.indexOf(el);

if (elIdx === -1) return;
const newRows = [...rows];

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

delete actionMap[user];
Expand Down

0 comments on commit e2cafd6

Please sign in to comment.