Even more le fixes
This commit is contained in:
@@ -47,6 +47,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const data: { [k: string]: any }[] = useLoaderData<typeof loader>();
|
const data: { [k: string]: any }[] = useLoaderData<typeof loader>();
|
||||||
|
const [gameModData, setGameModData] = useState(data);
|
||||||
const { isOpen, onClose, onOpen } = useDisclosure();
|
const { isOpen, onClose, onOpen } = useDisclosure();
|
||||||
const [idToAdd, setIdToAdd] = useState<string>("");
|
const [idToAdd, setIdToAdd] = useState<string>("");
|
||||||
const [nameToAdd, setNameToAdd] = useState<string>("");
|
const [nameToAdd, setNameToAdd] = useState<string>("");
|
||||||
@@ -74,11 +75,6 @@ export default function () {
|
|||||||
title: "Cannot add game mod",
|
title: "Cannot add game mod",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toast({
|
|
||||||
description: `${name} was added as a game mod`,
|
|
||||||
status: "success",
|
|
||||||
title: "Game mod added",
|
|
||||||
});
|
|
||||||
onClose();
|
onClose();
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
@@ -87,6 +83,39 @@ export default function () {
|
|||||||
setNameToAdd("");
|
setNameToAdd("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeMod(user: string) {
|
||||||
|
const response = await fetch("/api/gme/remove", {
|
||||||
|
body: JSON.stringify({ user }),
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
let msg = "Unknown error";
|
||||||
|
|
||||||
|
try {
|
||||||
|
msg = ((await response.json()) as { error: string }).error;
|
||||||
|
} catch {}
|
||||||
|
toast({
|
||||||
|
description: msg,
|
||||||
|
status: "error",
|
||||||
|
title: "Cannot remove game mod",
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
description: `${data.find((i) => i.metadata.id === user)?.name} was removed as a game mod`,
|
||||||
|
status: "success",
|
||||||
|
title: "Game mod removed",
|
||||||
|
});
|
||||||
|
|
||||||
|
setGameModData(gameModData.filter((i) => i.metadata.id !== user));
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container maxW="container.lg">
|
<Container maxW="container.lg">
|
||||||
<TableContainer>
|
<TableContainer>
|
||||||
@@ -102,7 +131,7 @@ export default function () {
|
|||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{data.map((item) => {
|
{gameModData.map((item) => {
|
||||||
return (
|
return (
|
||||||
<Tr key={item.metadata.id}>
|
<Tr key={item.metadata.id}>
|
||||||
<Td>{item.metadata.id}</Td>
|
<Td>{item.metadata.id}</Td>
|
||||||
|
|||||||
Reference in New Issue
Block a user