Watch as I break something lol
This commit is contained in:
parent
60d1473e79
commit
ee3ab13ae7
@ -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();
|
||||
|
||||
@ -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) {
|
||||
@ -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);
|
||||
@ -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({
|
||||
@ -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;
|
||||
@ -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(),
|
||||
@ -342,6 +356,7 @@ export default function () {
|
||||
true,
|
||||
);
|
||||
}}
|
||||
value={queue}
|
||||
>
|
||||
{entryTypes}
|
||||
</Select>
|
||||
|
Loading…
x
Reference in New Issue
Block a user