From bbaff35812d3c5df19510abf8731267f445f793e Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Thu, 26 Oct 2023 00:20:19 +0100 Subject: [PATCH] feat: group reports by author if not urgent --- app/panel/reports/page.tsx | 77 +++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/app/panel/reports/page.tsx b/app/panel/reports/page.tsx index 4c03ee8..4aaaefc 100644 --- a/app/panel/reports/page.tsx +++ b/app/panel/reports/page.tsx @@ -3,30 +3,73 @@ import { CardLink } from "@/components/common/CardLink"; import { Input } from "@/components/ui/input"; import { fetchOpenReports } from "@/lib/db"; import { PizzaIcon } from "lucide-react"; +import { Report } from "revolt-api"; export default async function Reports() { const reports = (await fetchOpenReports()) .reverse() .sort((b, _) => (b.content.report_reason.includes("Illegal") ? -1 : 0)); - return ( -
- - {reports.length - ? reports.map((report) => ( - - - - )) - : (<> -

- -

-

- You‘ve caught up for now. -

- ) + const byCategory: Record = { + Urgent: [], + All: [], + }; + const keyOrder = ["Urgent", "All"]; + + const countsByAuthor: Record = {}; + for (const report of reports) { + if (report.content.report_reason.includes("Illegal")) { + byCategory.Urgent.push(report); + } else { + countsByAuthor[report.author_id] = + (countsByAuthor[report.author_id] || 0) + 1; + } + } + + for (const report of reports) { + if (!report.content.report_reason.includes("Illegal")) { + if (countsByAuthor[report.author_id] > 1) { + if (!keyOrder.includes(report.author_id)) { + keyOrder.push(report.author_id); + byCategory[report.author_id] = []; + } + + byCategory[report.author_id].push(report); + } else { + byCategory.All.push(report); } + } + } + + return ( +
+ {/**/} + {reports.length ? ( + keyOrder.map((key) => { + return ( +
+

{key}

+ {byCategory[key].map((report) => ( + + + + ))}{" "} +
+ ); + }) + ) : ( + <> +

+ +

+

+ You‘ve caught up for now. +

+ + )}
); }