feat(solution): add layout and page components for problem solution, including footer

This commit is contained in:
cfngc4594 2025-03-10 20:54:31 +08:00
parent 4727c55bcc
commit 84ac0a88dc
3 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import prisma from "@/lib/prisma";
import ProblemSolutionFooter from "@/features/playground/problem/solution/footer";
interface ProblemSolutionLayoutProps {
params: Promise<{ id: string }>;
children: React.ReactNode;
}
export default async function ProblemSolutionLayout({
params,
children,
}: ProblemSolutionLayoutProps) {
const { id } = await params;
const problem = await prisma.problem.findUnique({
where: { id: parseInt(id) },
select: {
title: true,
},
});
const title = problem?.title ?? "";
return (
<div className="h-full flex flex-col">
<div className="flex-1">{children}</div>
<ProblemSolutionFooter title={title} />
</div>
);
}

View File

@ -0,0 +1,32 @@
import prisma from "@/lib/prisma";
import { notFound } from "next/navigation";
import { MdxRenderer } from "@/components/content/mdx-renderer";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
interface ProblemSolutionPageProps {
params: Promise<{ id: string }>;
}
export default async function ProblemSolutionPage({
params,
}: ProblemSolutionPageProps) {
const { id } = await params;
const problem = await prisma.problem.findUnique({
where: { id: parseInt(id) },
select: {
solution: true,
},
});
if (!problem) {
notFound();
}
return (
<ScrollArea className="[&>[data-radix-scroll-area-viewport]]:max-h-[calc(100vh-130px)]">
<MdxRenderer source={problem.solution} />
<ScrollBar orientation="horizontal" />
</ScrollArea>
);
}

View File

@ -0,0 +1,23 @@
import { cn } from "@/lib/utils";
interface ProblemSolutionFooterProps {
title: string;
className?: string;
}
export default function ProblemSolutionFooter({
title,
className,
...props
}: ProblemSolutionFooterProps) {
return (
<footer
{...props}
className={cn("h-9 flex flex-none items-center bg-muted px-3 py-2", className)}
>
<div className="w-full flex items-center justify-center">
<span className="truncate">Solution of {title}</span>
</div>
</footer>
);
}