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 }[],
|
[] as { element: ReactNode; id: string }[],
|
||||||
);
|
);
|
||||||
const [before, setBefore] = useState(Date.now());
|
const [before, setBefore] = useState(Date.now());
|
||||||
|
const [queue, setQueue] = useState("");
|
||||||
const messageChannel: MutableRefObject<MessageChannel | null> = useRef(null);
|
const messageChannel: MutableRefObject<MessageChannel | null> = useRef(null);
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
@ -155,8 +156,36 @@ export default function () {
|
|||||||
jump_item_to_top = false,
|
jump_item_to_top = false,
|
||||||
clear_all_others = false,
|
clear_all_others = false,
|
||||||
): Promise<void> {
|
): 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(
|
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) {
|
if (!queueReq.ok) {
|
||||||
@ -173,19 +202,10 @@ export default function () {
|
|||||||
return;
|
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();
|
let entryData: { [k: string]: any }[] = await queueReq.json();
|
||||||
const newEntries = clear_all_others ? [] : [...entries];
|
const newEntries = clear_all_others ? [] : [...entries];
|
||||||
|
|
||||||
if (
|
if (itemId && jump_item_to_top) {
|
||||||
itemId &&
|
|
||||||
itemType &&
|
|
||||||
["appeal", "gma", "inactivity", "report"].includes(itemType) &&
|
|
||||||
jump_item_to_top
|
|
||||||
) {
|
|
||||||
history.replaceState(null, "", location.origin + location.pathname);
|
history.replaceState(null, "", location.origin + location.pathname);
|
||||||
|
|
||||||
const specifiedItem = entryData.find((e) => e.id === itemId);
|
const specifiedItem = entryData.find((e) => e.id === itemId);
|
||||||
@ -194,7 +214,7 @@ export default function () {
|
|||||||
entryData = entryData.filter((entry) => entry.id !== specifiedItem.id);
|
entryData = entryData.filter((entry) => entry.id !== specifiedItem.id);
|
||||||
entryData.unshift(specifiedItem);
|
entryData.unshift(specifiedItem);
|
||||||
} else {
|
} else {
|
||||||
const itemReq = await fetch(`/api/mod-queue/${itemType}/${itemId}`);
|
const itemReq = await fetch(`/api/mod-queue/${queueType}/${itemId}`);
|
||||||
|
|
||||||
if (!itemReq.ok) {
|
if (!itemReq.ok) {
|
||||||
toast({
|
toast({
|
||||||
@ -221,15 +241,7 @@ export default function () {
|
|||||||
let cardType = queue_type;
|
let cardType = queue_type;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
entryData.indexOf(entry) === 0 &&
|
|
||||||
itemType &&
|
|
||||||
itemType !== queue_type
|
|
||||||
) {
|
|
||||||
cardType = itemType;
|
|
||||||
// Prevent duplicate items
|
|
||||||
} else if (
|
|
||||||
entryData.indexOf(entry) > 0 &&
|
entryData.indexOf(entry) > 0 &&
|
||||||
queue_type === cardType &&
|
|
||||||
entryData.filter((d) => d.id === entry.id).length > 1
|
entryData.filter((d) => d.id === entry.id).length > 1
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
@ -334,6 +346,8 @@ export default function () {
|
|||||||
|
|
||||||
const { target } = v;
|
const { target } = v;
|
||||||
|
|
||||||
|
setQueue(target.options[target.selectedIndex].value);
|
||||||
|
|
||||||
await updateQueue(
|
await updateQueue(
|
||||||
target.options[target.selectedIndex].value,
|
target.options[target.selectedIndex].value,
|
||||||
Date.now(),
|
Date.now(),
|
||||||
@ -342,6 +356,7 @@ export default function () {
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
value={queue}
|
||||||
>
|
>
|
||||||
{entryTypes}
|
{entryTypes}
|
||||||
</Select>
|
</Select>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user