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-03-07 08:34:51 +00:00
|
|
|
import { Difficulty } from "@prisma/client";
|
|
|
|
|
2025-03-12 05:57:57 +00:00
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
2025-03-07 08:34:51 +00:00
|
|
|
const getDifficultyColor = (difficulty: Difficulty) => {
|
|
|
|
switch (difficulty) {
|
|
|
|
case "EASY":
|
|
|
|
return "text-green-500";
|
|
|
|
case "MEDIUM":
|
|
|
|
return "text-yellow-500";
|
|
|
|
case "HARD":
|
|
|
|
return "text-red-500";
|
|
|
|
default:
|
|
|
|
return "text-gray-500";
|
|
|
|
}
|
|
|
|
};
|
2025-03-07 07:52:11 +00:00
|
|
|
|
|
|
|
export default async function ProblemsetPage() {
|
|
|
|
const problems = await prisma.problem.findMany({
|
|
|
|
where: { published: true },
|
2025-03-12 04:52:50 +00:00
|
|
|
orderBy: {
|
|
|
|
id: "asc",
|
|
|
|
},
|
2025-03-14 10:59:44 +00:00
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
difficulty: true,
|
|
|
|
},
|
2025-03-07 07:52:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Table>
|
|
|
|
<TableHeader className="bg-transparent">
|
|
|
|
<TableRow className="hover:bg-transparent">
|
|
|
|
<TableHead className="w-1/3">Id</TableHead>
|
|
|
|
<TableHead className="w-1/3">Title</TableHead>
|
|
|
|
<TableHead className="w-1/3">Difficulty</TableHead>
|
|
|
|
</TableRow>
|
|
|
|
</TableHeader>
|
|
|
|
<tbody aria-hidden="true" className="table-row h-2"></tbody>
|
|
|
|
<TableBody className="[&_td:first-child]:rounded-l-lg [&_td:last-child]:rounded-r-lg">
|
|
|
|
{problems.map((problem) => (
|
|
|
|
<TableRow
|
|
|
|
key={problem.id}
|
|
|
|
className="odd:bg-muted/50 odd:hover:bg-muted/50 border-none hover:bg-transparent"
|
|
|
|
>
|
2025-03-07 08:26:00 +00:00
|
|
|
<TableCell className="py-2.5">
|
|
|
|
<Link
|
|
|
|
href={`/problems/${problem.id}`}
|
|
|
|
className="hover:text-blue-500"
|
|
|
|
>
|
|
|
|
{problem.id}
|
|
|
|
</Link>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className="py-2.5">
|
|
|
|
<Link
|
|
|
|
href={`/problems/${problem.id}`}
|
|
|
|
className="hover:text-blue-500"
|
|
|
|
>
|
|
|
|
{problem.title}
|
|
|
|
</Link>
|
|
|
|
</TableCell>
|
2025-03-12 04:52:50 +00:00
|
|
|
<TableCell className={`py-2.5 ${getDifficultyColor(problem.difficulty)}`}>
|
2025-03-07 08:26:00 +00:00
|
|
|
{problem.difficulty}
|
|
|
|
</TableCell>
|
2025-03-07 07:52:11 +00:00
|
|
|
</TableRow>
|
|
|
|
))}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
|
|
|
);
|
|
|
|
}
|