From 8df681e520c74a264d0a853d0093caef31da534d Mon Sep 17 00:00:00 2001 From: Regalijan Date: Sun, 10 Mar 2024 00:48:20 -0500 Subject: [PATCH] Add events member data to me page --- app/routes/me.tsx | 71 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/app/routes/me.tsx b/app/routes/me.tsx index 1803f93..ef0cbbd 100644 --- a/app/routes/me.tsx +++ b/app/routes/me.tsx @@ -11,6 +11,7 @@ import { ModalHeader, ModalOverlay, Table, + TableCaption, TableContainer, Tbody, Td, @@ -44,8 +45,39 @@ export async function loader({ context }: { context: RequestContext }) { ); const settledPromises = await Promise.allSettled(d1Promises); + let etData: { [k: string]: any } | null = null; + + if (currentUser.permissions & (1 << 3)) { + etData = await context.env.D1.prepare( + "SELECT name, points, roblox_id FROM et_members WHERE id = ?;", + ) + .bind(currentUser.id) + .first(); + + if (etData) { + const now = new Date(); + const pointsData = await context.env.D1.prepare( + "SELECT answered_at, approved, day, month, performed_at, reached_minimum_player_count, type, year FROM events WHERE created_by = ? AND month = ? AND year = ?;", + ) + .bind(currentUser.id, now.getUTCMonth(), now.getUTCFullYear()) + .all(); + + for (const row of pointsData.results as Record[]) { + if (row.performed_at) etData.points += 10; + if (row.type === "gamenight" && row.reached_minimum_player_count) + etData.points += 10; + if ( + row.type === "rotw" && + row.answered_at - row.performed_at >= 86400000 + ) + etData.points += 10; + if (!row.performed_at && row.day < now.getUTCDate()) etData.points -= 5; + } + } + } return { + etData, items: settledPromises.map((p) => { if (p.status === "fulfilled") return p.value.results; @@ -57,6 +89,7 @@ export async function loader({ context }: { context: RequestContext }) { export default function () { const data: { + etData: { [k: string]: any } | null; items: ({ [k: string]: any }[] | null)[]; permissions: number; } = useLoaderData(); @@ -237,6 +270,36 @@ export default function () { My Data

+ {data.permissions & (1 << 3) ? ( + <> + Events Team Info + + + + Reach out to ETM if this info is incorrect + + + + + + + + + + {data.etData?.name} + {data.etData?.points} + + + {data.etData?.roblox_id} + + + +
NamePointsRoblox ID
+
+ + ) : null} Discord Appeals @@ -258,8 +321,8 @@ export default function () { {result.open ? "Pending" : typeof result.approved === "number" - ? `${result.approved ? "Accepted" : "Denied"}` - : "Unknown"} + ? `${result.approved ? "Accepted" : "Denied"}` + : "Unknown"}