mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(solution): add layout and page components for problem solution, including footer
This commit is contained in:
parent
4727c55bcc
commit
84ac0a88dc
30
src/app/(app)/problems/[id]/@problem/@solution/layout.tsx
Normal file
30
src/app/(app)/problems/[id]/@problem/@solution/layout.tsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
32
src/app/(app)/problems/[id]/@problem/@solution/page.tsx
Normal file
32
src/app/(app)/problems/[id]/@problem/@solution/page.tsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
23
src/features/playground/problem/solution/footer.tsx
Normal file
23
src/features/playground/problem/solution/footer.tsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user