Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Display inactivity notices in the mod queue
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 17bca65 commit 0b5e82b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions app/routes/mod-queue.tsx
Expand Up @@ -16,14 +16,15 @@ import {
useToast,
VStack,
} from "@chakra-ui/react";
import { useEffect, useState } from "react";
import { type ReactElement, useEffect, useState } from "react";
import AppealCard from "../../components/AppealCard.js";
import GameAppealCard from "../../components/GameAppealCard.js";
import NewGameBan from "../../components/NewGameBan.js";
import NewInfractionModal from "../../components/NewInfractionModal.js";
import ReportCard from "../../components/ReportCard.js";
import { useLoaderData } from "@remix-run/react";
import NewInactivityNotice from "../../components/NewInactivityNotice.js";
import InactivityNoticeCard from "../../components/InactivityNoticeCard.js";

export async function loader({ context }: { context: RequestContext }) {
const { current_user: currentUser } = context.data;
Expand Down Expand Up @@ -108,23 +109,23 @@ export default function () {
const pageProps = useLoaderData<typeof loader>();
const isDesktop = useBreakpointValue({ base: false, lg: true });
const entryTypes = [];
const [entries, setEntries] = useState([] as JSX.Element[]);
const [before, setBefore] = useState(0);
const [entries, setEntries] = useState([] as ReactElement[]);
const [before, setBefore] = useState(Date.now());

for (const type of pageProps.entry_types)
entryTypes.push(
<option key={type.value} value={type.value}>
{type.name}
</option>
</option>,
);

async function updateQueue(
queue_type: string,
before = Date.now(),
show_closed = false
before: number,
show_closed = false,
): Promise<void> {
const queueReq = await fetch(
`/api/mod-queue/list?before=${before}&showClosed=${show_closed}&type=${queue_type}`
`/api/mod-queue/list?before=${before}&showClosed=${show_closed}&type=${queue_type}`,
);

if (!queueReq.ok) {
Expand All @@ -148,7 +149,11 @@ export default function () {
const entryData: { [k: string]: any }[] = await queueReq.json();
const newEntries = [...entries];

if (itemId && itemType && ["appeal", "gma", "report"].includes(itemType)) {
if (
itemId &&
itemType &&
["appeal", "gma", "inactivity", "report"].includes(itemType)
) {
const itemReq = await fetch(`/api/mod-queue/${itemType}/${itemId}`);

if (!itemReq.ok) {
Expand Down Expand Up @@ -180,6 +185,13 @@ export default function () {

break;

case "inactivity":
newEntries.push(
<InactivityNoticeCard {...(entry as InactivityNoticeProps)} />,
);

break;

case "report":
newEntries.push(<ReportCard {...(entry as ReportCardProps)} />);

Expand All @@ -206,7 +218,7 @@ export default function () {

useEffect(() => {
(async function () {
await updateQueue(pageProps.entry_types[0].value);
await updateQueue(pageProps.entry_types[0].value, before);
})();

const searchParams = new URLSearchParams(location.search);
Expand Down

0 comments on commit 0b5e82b

Please sign in to comment.