2025-03-07 08:26:00 +00:00
|
|
|
import Link from "next/link";
|
2025-03-07 07:52:11 +00:00
|
|
|
import {
|
|
|
|
Table,
|
|
|
|
TableBody,
|
|
|
|
TableCell,
|
|
|
|
TableHead,
|
|
|
|
TableHeader,
|
|
|
|
TableRow,
|
|
|
|
} from "@/components/ui/table";
|
|
|
|
import prisma from "@/lib/prisma";
|
2025-04-14 09:22:01 +00:00
|
|
|
import { auth } from "@/lib/auth";
|
2025-03-30 13:04:23 +00:00
|
|
|
import { getDifficultyColorClass } from "@/lib/utils";
|
2025-04-14 09:35:31 +00:00
|
|
|
import { CircleCheckBigIcon, CircleDotIcon } from "lucide-react";
|
2025-03-07 07:52:11 +00:00
|
|
|
|
|
|
|
export default async function ProblemsetPage() {
|
|
|
|
const problems = await prisma.problem.findMany({
|
|
|
|
where: { published: true },
|
2025-04-14 09:35:31 +00:00
|
|
|
orderBy: { id: "asc" },
|
|
|
|
select: { id: true, title: true, difficulty: true },
|
2025-03-07 07:52:11 +00:00
|
|
|
});
|
|
|
|
|
2025-04-14 09:22:01 +00:00
|
|
|
const session = await auth();
|
2025-04-14 09:35:31 +00:00
|
|
|
const userId = session?.user?.id;
|
2025-04-14 09:22:01 +00:00
|
|
|
|
2025-04-14 09:35:31 +00:00
|
|
|
const submissions = userId
|
|
|
|
? await prisma.submission.findMany({
|
|
|
|
where: { userId },
|
|
|
|
select: { problemId: true, status: true },
|
|
|
|
})
|
|
|
|
: [];
|
2025-04-14 09:22:01 +00:00
|
|
|
|
2025-04-14 09:35:31 +00:00
|
|
|
const completedProblems = new Set(submissions.filter(s => s.status === "AC").map(s => s.problemId));
|
|
|
|
const attemptedProblems = new Set(submissions.filter(s => s.status !== "AC").map(s => s.problemId));
|
2025-04-14 09:22:01 +00:00
|
|
|
|
2025-03-07 07:52:11 +00:00
|
|
|
return (
|
|
|
|
<Table>
|
|
|
|
<TableHeader className="bg-transparent">
|
|
|
|
<TableRow className="hover:bg-transparent">
|
2025-04-14 09:22:01 +00:00
|
|
|
<TableHead className="w-1/3">Status</TableHead>
|
2025-03-07 07:52:11 +00:00
|
|
|
<TableHead className="w-1/3">Title</TableHead>
|
|
|
|
<TableHead className="w-1/3">Difficulty</TableHead>
|
|
|
|
</TableRow>
|
|
|
|
</TableHeader>
|
|
|
|
<TableBody className="[&_td:first-child]:rounded-l-lg [&_td:last-child]:rounded-r-lg">
|
2025-03-22 04:30:04 +00:00
|
|
|
{problems.map((problem, index) => (
|
2025-03-07 07:52:11 +00:00
|
|
|
<TableRow
|
|
|
|
key={problem.id}
|
2025-04-05 15:34:48 +00:00
|
|
|
className="h-10 border-b-0 odd:bg-muted/50 hover:text-blue-500 hover:bg-muted"
|
2025-03-07 07:52:11 +00:00
|
|
|
>
|
2025-03-07 08:26:00 +00:00
|
|
|
<TableCell className="py-2.5">
|
2025-04-14 09:35:31 +00:00
|
|
|
{userId && (completedProblems.has(problem.id) ? (
|
|
|
|
<CircleCheckBigIcon className="text-green-500" size={18} aria-hidden="true" />
|
|
|
|
) : attemptedProblems.has(problem.id) ? (
|
|
|
|
<CircleDotIcon className="text-yellow-500" size={18} aria-hidden="true" />
|
|
|
|
) : null)}
|
2025-03-07 08:26:00 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell className="py-2.5">
|
2025-04-14 09:35:31 +00:00
|
|
|
<Link href={`/problems/${problem.id}`} className="hover:text-blue-500">
|
2025-04-14 09:22:01 +00:00
|
|
|
{index + 1}. {problem.title}
|
2025-03-07 08:26:00 +00:00
|
|
|
</Link>
|
|
|
|
</TableCell>
|
2025-03-30 13:04:23 +00:00
|
|
|
<TableCell className={`py-2.5 ${getDifficultyColorClass(problem.difficulty)}`}>
|
2025-03-07 08:26:00 +00:00
|
|
|
{problem.difficulty}
|
|
|
|
</TableCell>
|
2025-03-07 07:52:11 +00:00
|
|
|
</TableRow>
|
|
|
|
))}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
|
|
|
);
|
|
|
|
}
|