Another attempt to fix removing users on game ban modal
This commit is contained in:
parent
2964beb998
commit
e2cafd60b6
@ -27,6 +27,7 @@ import { type ReactElement, useState } from "react";
|
|||||||
export default function (props: { isOpen: boolean; onClose: () => void }) {
|
export default function (props: { isOpen: boolean; onClose: () => void }) {
|
||||||
const actionMap: { [k: string]: number } = {};
|
const actionMap: { [k: string]: number } = {};
|
||||||
const [rows, setRows] = useState([] as ReactElement[]);
|
const [rows, setRows] = useState([] as ReactElement[]);
|
||||||
|
const [users, setUsers] = useState([] as string[]);
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const fileTypes: { [k: string]: string } = {
|
const fileTypes: { [k: string]: string } = {
|
||||||
gif: "image/gif",
|
gif: "image/gif",
|
||||||
@ -46,6 +47,9 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function addUser(user: string) {
|
function addUser(user: string) {
|
||||||
|
const newUsers = [...users];
|
||||||
|
newUsers.push(user);
|
||||||
|
|
||||||
const newRows = [...rows];
|
const newRows = [...rows];
|
||||||
newRows.push(
|
newRows.push(
|
||||||
<Tr key={user}>
|
<Tr key={user}>
|
||||||
@ -71,20 +75,21 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
|
|||||||
</Tr>,
|
</Tr>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
setUsers(newUsers);
|
||||||
setRows(newRows);
|
setRows(newRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeUser(user: string) {
|
function removeUser(user: string) {
|
||||||
|
const newUsers = [...users];
|
||||||
|
const userIdx = newUsers.indexOf(user);
|
||||||
|
|
||||||
|
if (userIdx === -1) return;
|
||||||
|
|
||||||
const newRows = [...rows];
|
const newRows = [...rows];
|
||||||
const el = newRows.find((el) => el.key === user);
|
|
||||||
|
|
||||||
if (!el) return;
|
newUsers.splice(userIdx, 1);
|
||||||
|
newRows.splice(userIdx, 1);
|
||||||
const elIdx = newRows.indexOf(el);
|
setUsers(newUsers);
|
||||||
|
|
||||||
if (elIdx === -1) return;
|
|
||||||
|
|
||||||
newRows.splice(elIdx, 1);
|
|
||||||
setRows(newRows);
|
setRows(newRows);
|
||||||
|
|
||||||
delete actionMap[user];
|
delete actionMap[user];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user