From d9a9a9f33521f0bdcc276f78667d233e2ec667d2 Mon Sep 17 00:00:00 2001
From: regalijan <r@regalijan.com>
Date: Thu, 19 Oct 2023 16:49:08 -0400
Subject: [PATCH] Create server handler for mod queue page

---
 pages/mod-queue.page.server.tsx | 34 +++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/pages/mod-queue.page.server.tsx b/pages/mod-queue.page.server.tsx
index ca51cae..1a999ce 100644
--- a/pages/mod-queue.page.server.tsx
+++ b/pages/mod-queue.page.server.tsx
@@ -4,11 +4,25 @@ export async function onBeforeRender(pageContext: PageContext) {
   if (!currentUser)
     return {
       pageContext: {
-        logged_in: false,
+        pageProps: {
+          logged_in: false,
+        },
+        status: 401,
       },
-      status: 401,
     };
 
+  const newItemPermissions = {
+    game_ban: [1 << 5],
+    inactivity: [1 << 2, 1 << 9, 1 << 10],
+    infraction: [1 << 0, 1 << 2, 1 << 6, 1 << 7]
+  };
+
+  const newItemNames: { [k: string]: string } = {
+    game_ban: "Game Ban",
+    inactivity: "Inactivity Notice",
+    infraction: "Infraction",
+  };
+
   const typePermissions = {
     appeal: [1 << 0, 1 << 1],
     gma: [1 << 5],
@@ -21,8 +35,14 @@ export async function onBeforeRender(pageContext: PageContext) {
     report: "Game Reports",
   };
 
+  const allowedNewItems = [];
   const allowedTypes = [];
 
+  for (const [item, ints] of Object.entries(newItemPermissions)) {
+    if (ints.find((i) => currentUser.permissions & i))
+      allowedNewItems.push({ name: newItemNames[item], value: item })
+  }
+
   for (const [type, ints] of Object.entries(typePermissions)) {
     if (ints.find((i) => currentUser.permissions & i))
       allowedTypes.push({ name: typeNames[type], value: type });
@@ -31,15 +51,21 @@ export async function onBeforeRender(pageContext: PageContext) {
   if (!allowedTypes.length)
     return {
       pageContext: {
-        entry_types: [],
+        pageProps: {
+          entry_types: [],
+          item_types: [],
+          logged_in: true,
+        },
+        status: 403,
       },
-      status: 403,
     };
 
   return {
     pageContext: {
       pageProps: {
         entry_types: allowedTypes,
+        item_types: allowedNewItems,
+        logged_in: true,
       },
     },
   };