"Finish" this atrocity

This commit is contained in:
Regalijan 2023-10-23 19:52:29 -04:00
parent 6ca0e70aa4
commit 58f83d2809
Signed by untrusted user who does not match committer: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -45,22 +45,29 @@ export async function loader({ context }: { context: RequestContext }) {
const settledPromises = await Promise.allSettled(d1Promises);
return settledPromises.filter((p) => {
if (p.status === "fulfilled") return p.value.results;
const data = {
items: settledPromises.filter((p) => {
if (p.status === "fulfilled") return p.value.results;
return null;
}) as any as ({ [k: string]: any }[] | null)[];
return null;
}) as any as ({ [k: string]: any }[] | null)[],
permissions: currentUser.permissions as number,
};
return data;
}
export default function () {
const data: ({ [k: string]: any }[] | null)[] =
useLoaderData<typeof loader>();
const data: {
items: ({ [k: string]: any }[] | null)[];
permissions: number;
} = useLoaderData<typeof loader>();
const timeStates: {
[k: number]: { data: string; set: Dispatch<SetStateAction<string>> };
} = {};
const toast = useToast();
for (const result of data) {
for (const result of data.items) {
if (!result) continue;
for (const row of result) {
@ -231,6 +238,88 @@ export default function () {
<br />
<br />
<Heading size="lg">Discord Appeals</Heading>
<TableContainer mb="16px">
<Table variant="simple">
<Thead>
<Tr>
<Th>Date</Th>
<Th>ID</Th>
<Th>Status</Th>
<Th>View</Th>
</Tr>
</Thead>
<Tbody>
{data.items[0]?.map((result) => {
return (
<Tr>
<Td>{timeStates[result.created_at].data}</Td>
<Td>{result.id}</Td>
<Td>
{result.open
? "Pending"
: typeof result.approved === "boolean"
? `${result.approved ? "Accepted" : "Denied"}`
: "Unknown"}
</Td>
<Td>
<Button
onClick={async () => await fetchItem(result.id, "appeal")}
>
View
</Button>
</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>
<br />
{[1 << 2, 1 << 3, 1 << 9, 1 << 10].find((p) => data.permissions & p) ? (
<>
<Heading size="lg">Inactivity Notices</Heading>
<TableContainer mb="16px">
<Table variant="simple">
<Thead>
<Tr>
<Th>Date</Th>
<Th>ID</Th>
<Th>Status</Th>
<Th>View</Th>
</Tr>
</Thead>
<Tbody>
{data.items[1]?.map((result) => {
return (
<Tr>
<Td>{timeStates[result.created_at].data}</Td>
<Td>{result.id}</Td>
<Td>
{result.open
? "Pending"
: Object.values(result.decisions).find((d) => !d)
? "Denied"
: "Approved"}
</Td>
<Td>
<Button
onClick={async () =>
await fetchItem(result.id, "inactivity")
}
>
View
</Button>
</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>
<br />
</>
) : null}
<Heading size="lg">Reports</Heading>
<TableContainer>
<Table variant="simple">
<Thead>
@ -242,32 +331,22 @@ export default function () {
</Tr>
</Thead>
<Tbody>
{data[0]
? data[0].map((result) => {
return (
<Tr>
<Td>{timeStates[result.created_at].data}</Td>
<Td>{result.id}</Td>
<Td>
{result.open
? "Pending"
: typeof result.approved === "boolean"
? `${result.approved ? "Accepted" : "Denied"}`
: "Unknown"}
</Td>
<Td>
<Button
onClick={async () =>
await fetchItem(result.id, "appeal")
}
>
View
</Button>
</Td>
</Tr>
);
})
: undefined}
{data.items[2]?.map((result) => {
return (
<Tr>
<Td>{timeStates[result.created_at].data}</Td>
<Td>{result.id}</Td>
<Td>{result.open ? "Pending" : "Reviewed"}</Td>
<Td>
<Button
onClick={async () => await fetchItem(result.id, "report")}
>
View
</Button>
</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>