import { notFound } from "next/navigation"; import { headers } from "next/headers"; import { auth } from "@/lib/auth/server"; import { db, recipes, eq, and } from "@epicure/db"; import { PrintTrigger } from "@/components/recipe/print-trigger"; import { hasQuantity } from "@/lib/fractions"; type Params = { params: Promise<{ id: string }> }; export default async function RecipePrintPage({ params }: Params) { const { id } = await params; const session = await auth.api.getSession({ headers: await headers() }); if (!session) return null; const recipe = await db.query.recipes.findFirst({ where: and(eq(recipes.id, id), eq(recipes.authorId, session.user.id)), with: { ingredients: { orderBy: (t, { asc }) => asc(t.order) }, steps: { orderBy: (t, { asc }) => asc(t.order) }, }, }); if (!recipe) notFound(); const totalMins = (recipe.prepMins ?? 0) + (recipe.cookMins ?? 0); const DIETARY_LABELS: Record = { vegan: "Vegan", vegetarian: "Vegetarian", glutenFree: "Gluten-free", dairyFree: "Dairy-free", nutFree: "Nut-free", halal: "Halal", kosher: "Kosher", }; const activeTags = Object.entries(recipe.dietaryTags ?? {}) .filter(([, v]) => v) .map(([k]) => DIETARY_LABELS[k]) .filter(Boolean); return ( <>

{recipe.title}

{recipe.description && (

{recipe.description}

)}
{recipe.baseServings && Serves {recipe.baseServings}} {recipe.prepMins && Prep {recipe.prepMins} min} {recipe.cookMins && Cook {recipe.cookMins} min} {totalMins > 0 && Total {totalMins} min} {recipe.difficulty && {recipe.difficulty.charAt(0).toUpperCase() + recipe.difficulty.slice(1)}}
{activeTags.length > 0 && (
{activeTags.map((tag) => ( {tag} ))}
)} {recipe.ingredients.length > 0 && ( <>

Ingredients

    {recipe.ingredients.map((ing) => (
  • {[hasQuantity(ing.quantity) ? ing.quantity : null, ing.unit].filter(Boolean).join(" ")} {ing.rawName} {ing.note && ({ing.note})}
  • ))}
)} {recipe.steps.length > 0 && ( <>

Instructions

    {recipe.steps.map((step) => (
  1. {step.instruction} {step.timerSeconds && ( ⏱ {Math.floor(step.timerSeconds / 60)} min )}
  2. ))}
)}
); }