import { ReportCard } from "@/components/cards/ReportCard"; import { CardLink } from "@/components/common/CardLink"; import { Input } from "@/components/ui/input"; import { fetchOpenReports, fetchUsersById } 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)); const byCategory: Record = { Urgent: [], All: [], AssignedToCase: [], }; const keyOrder = ["Urgent", "All"]; const countsByAuthor: Record = {}; for (const report of reports) { if (report.case_id) { byCategory.AssignedToCase.push(report); } else 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); } } } const authorNames: Record = {}; for (const user of await fetchUsersById(Object.keys(countsByAuthor))) { authorNames[user._id] = user.username + "#" + user.discriminator; } return (
{/**/} {reports.length ? ( keyOrder .filter((key) => byCategory[key].length) .map((key) => { return (

{authorNames[key] ?? key}

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

You‘ve caught up for now.

)} {byCategory["AssignedToCase"].length && (

Reports assigned to cases

{byCategory["AssignedToCase"].map((report) => ( ))}
)}
); }