Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Watch as I break something lol
  • Loading branch information
regalijan committed Oct 30, 2023
1 parent 60d1473 commit ee3ab13
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions app/routes/mod-queue.tsx
Expand Up @@ -128,6 +128,7 @@ export default function () {
[] as { element: ReactNode; id: string }[],
);
const [before, setBefore] = useState(Date.now());
const [queue, setQueue] = useState("");
const messageChannel: MutableRefObject<MessageChannel | null> = useRef(null);
const toast = useToast();

Expand Down Expand Up @@ -155,8 +156,36 @@ export default function () {
jump_item_to_top = false,
clear_all_others = false,
): Promise<void> {
const searchParams = new URLSearchParams(location.search);
const itemId = searchParams.get("id");
const queueType = searchParams.get("type") ?? queue_type;

if (!pageProps.entry_types.find((type) => type.value === queueType)) {
toast({
description: "You cannot access that queue",
isClosable: true,
status: "error",
title: "Forbidden",
});

return;
}

if (!searchParams.get("type") && itemId) {
toast({
description: "Cannot load item by id without type",
isClosable: true,
status: "error",
title: "Bad link",
});

return;
}

if (queueType !== queue_type) setQueue(queueType);

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=${queueType}`,
);

if (!queueReq.ok) {
Expand All @@ -173,19 +202,10 @@ export default function () {
return;
}

const searchParams = new URLSearchParams(location.search);
const itemId = searchParams.get("id");
const itemType = searchParams.get("type");

let entryData: { [k: string]: any }[] = await queueReq.json();
const newEntries = clear_all_others ? [] : [...entries];

if (
itemId &&
itemType &&
["appeal", "gma", "inactivity", "report"].includes(itemType) &&
jump_item_to_top
) {
if (itemId && jump_item_to_top) {
history.replaceState(null, "", location.origin + location.pathname);

const specifiedItem = entryData.find((e) => e.id === itemId);
Expand All @@ -194,7 +214,7 @@ export default function () {
entryData = entryData.filter((entry) => entry.id !== specifiedItem.id);
entryData.unshift(specifiedItem);
} else {
const itemReq = await fetch(`/api/mod-queue/${itemType}/${itemId}`);
const itemReq = await fetch(`/api/mod-queue/${queueType}/${itemId}`);

if (!itemReq.ok) {
toast({
Expand All @@ -221,15 +241,7 @@ export default function () {
let cardType = queue_type;

if (
entryData.indexOf(entry) === 0 &&
itemType &&
itemType !== queue_type
) {
cardType = itemType;
// Prevent duplicate items
} else if (
entryData.indexOf(entry) > 0 &&
queue_type === cardType &&
entryData.filter((d) => d.id === entry.id).length > 1
)
continue;
Expand Down Expand Up @@ -334,6 +346,8 @@ export default function () {

const { target } = v;

setQueue(target.options[target.selectedIndex].value);

await updateQueue(
target.options[target.selectedIndex].value,
Date.now(),
Expand All @@ -342,6 +356,7 @@ export default function () {
true,
);
}}
value={queue}
>
{entryTypes}
</Select>
Expand Down

0 comments on commit ee3ab13

Please sign in to comment.