Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Try fixing again
  • Loading branch information
regalijan committed Mar 14, 2025
1 parent 2245b04 commit c48ca6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
29 changes: 9 additions & 20 deletions components/AppealBans.tsx
Expand Up @@ -19,32 +19,13 @@ import {
} from "@chakra-ui/react";
import { useEffect, useState } from "react";
import NewAppealBan from "./NewAppealBan.js";
import { useLoaderData } from "@remix-run/react";

export async function loader({ context }: { context: RequestContext }) {
const list = (
await context.env.D1.prepare(
"SELECT * FROM appeal_bans ORDER BY created_at DESC;",
).all()
).results as {
created_at: number | string;
created_by: string;
user: string;
}[];

for (const row of list)
row.created_at = new Date(row.created_at).toUTCString();

return list;
}

export default function (props: { isOpen: boolean; onClose: () => void }) {
const [entries, setEntries] = useState(
[] as { created_at: number | string; created_by: string; user: string }[],
);
const toast = useToast();
const { isOpen, onClose, onOpen } = useDisclosure();
setEntries(useLoaderData<typeof loader>());

async function removeBan(user: string) {
const removeResp = await fetch(`/api/appeals/${user}/ban`, {
Expand Down Expand Up @@ -80,7 +61,15 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
setEntries([...entries].filter((entry) => entry.user !== user));
}

useEffect(() => {}, []);
useEffect(() => {
(async function () {
const banData = await fetch("/api/appeals/bans");

if (!banData.ok) return;

setEntries(await banData.json());
});
}, []);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion functions/api/appeals/bans.ts
Expand Up @@ -2,7 +2,7 @@ import { jsonResponse } from "../../common.js";

export async function onRequestGet(context: RequestContext) {
const { results } = await context.env.D1.prepare(
"SELECT * FROM appeal_bans;",
"SELECT * FROM appeal_bans ORDER BY created_by DESC;",
).all();

return jsonResponse(JSON.stringify(results));
Expand Down

0 comments on commit c48ca6f

Please sign in to comment.