Another attempt to fix removing users on game ban modal

This commit is contained in:
regalijan 2023-10-19 16:50:47 -04:00
parent 2964beb998
commit e2cafd60b6
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -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",
@ -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}>
@ -71,20 +75,21 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
</Tr>,
);
setUsers(newUsers);
setRows(newRows);
}
function removeUser(user: string) {
const newUsers = [...users];
const userIdx = newUsers.indexOf(user);
if (userIdx === -1) return;
const newRows = [...rows];
const el = newRows.find((el) => el.key === user);
if (!el) return;
const elIdx = newRows.indexOf(el);
if (elIdx === -1) return;
newRows.splice(elIdx, 1);
newUsers.splice(userIdx, 1);
newRows.splice(userIdx, 1);
setUsers(newUsers);
setRows(newRows);
delete actionMap[user];