feat(problemset): add completion status indicator for problems

This commit is contained in:
cfngc4594 2025-04-14 17:22:01 +08:00
parent 59e133f29c
commit 0694e4dea0

View File

@ -8,6 +8,8 @@ import {
TableRow, TableRow,
} from "@/components/ui/table"; } from "@/components/ui/table";
import prisma from "@/lib/prisma"; import prisma from "@/lib/prisma";
import { auth } from "@/lib/auth";
import { CircleCheckBigIcon } from "lucide-react";
import { getDifficultyColorClass } from "@/lib/utils"; import { getDifficultyColorClass } from "@/lib/utils";
export default async function ProblemsetPage() { export default async function ProblemsetPage() {
@ -23,11 +25,28 @@ export default async function ProblemsetPage() {
}, },
}); });
const session = await auth();
let completedProblems: string[] = [];
if (session?.user) {
const submissions = await prisma.submission.findMany({
where: {
userId: session.user.id,
status: "AC",
},
select: {
problemId: true,
},
});
completedProblems = submissions.map(sub => sub.problemId);
}
return ( return (
<Table> <Table>
<TableHeader className="bg-transparent"> <TableHeader className="bg-transparent">
<TableRow className="hover:bg-transparent"> <TableRow className="hover:bg-transparent">
<TableHead className="w-1/3">Id</TableHead> <TableHead className="w-1/3">Status</TableHead>
<TableHead className="w-1/3">Title</TableHead> <TableHead className="w-1/3">Title</TableHead>
<TableHead className="w-1/3">Difficulty</TableHead> <TableHead className="w-1/3">Difficulty</TableHead>
</TableRow> </TableRow>
@ -40,19 +59,20 @@ export default async function ProblemsetPage() {
className="h-10 border-b-0 odd:bg-muted/50 hover:text-blue-500 hover:bg-muted" className="h-10 border-b-0 odd:bg-muted/50 hover:text-blue-500 hover:bg-muted"
> >
<TableCell className="py-2.5"> <TableCell className="py-2.5">
<Link {session?.user && completedProblems.includes(problem.id) && (
href={`/problems/${problem.id}`} <CircleCheckBigIcon
className="hover:text-blue-500" className="text-green-500"
> size={16}
{index + 1} aria-hidden="true"
</Link> />
)}
</TableCell> </TableCell>
<TableCell className="py-2.5"> <TableCell className="py-2.5">
<Link <Link
href={`/problems/${problem.id}`} href={`/problems/${problem.id}`}
className="hover:text-blue-500" className="hover:text-blue-500"
> >
{problem.title} {index + 1}. {problem.title}
</Link> </Link>
</TableCell> </TableCell>
<TableCell className={`py-2.5 ${getDifficultyColorClass(problem.difficulty)}`}> <TableCell className={`py-2.5 ${getDifficultyColorClass(problem.difficulty)}`}>