feat(problem-description): add dynamic title to footer and fetch problem title

This commit is contained in:
cfngc4594 2025-03-09 14:49:59 +08:00
parent ef753dd6c8
commit 163dc4b57c
2 changed files with 19 additions and 3 deletions

View File

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

View File

@ -1,10 +1,12 @@
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
interface ProblemDescriptionFooterProps { interface ProblemDescriptionFooterProps {
title: string;
className?: string; className?: string;
} }
export default function ProblemDescriptionFooter({ export default function ProblemDescriptionFooter({
title,
className, className,
...props ...props
}: ProblemDescriptionFooterProps) { }: ProblemDescriptionFooterProps) {
@ -14,7 +16,7 @@ export default function ProblemDescriptionFooter({
className={cn("h-9 flex flex-none items-center bg-muted px-3 py-2", className)} 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"> <div className="w-full flex items-center justify-center">
<span className="truncate">Description of Two Sum</span> <span className="truncate">Description of {title}</span>
</div> </div>
</footer> </footer>
); );