-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
158 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { prisma } from "@/data"; | ||
import Image from "next/image"; | ||
import { notFound } from "next/navigation"; | ||
interface Params { | ||
categorySlug: string; | ||
recipeSlug: string; | ||
imageId: string; | ||
} | ||
|
||
interface Props { | ||
params: Promise<Params>; | ||
} | ||
export default async function Page({ params }: Props) { | ||
const { imageId } = await params; | ||
|
||
const galleryImage = await prisma.recipeGalleryImage.findUnique({ | ||
where: { | ||
id: parseInt(imageId), | ||
}, | ||
}); | ||
|
||
if (!galleryImage) { | ||
return notFound(); | ||
} | ||
|
||
return ( | ||
<dialog id="gallery-modal" suppressHydrationWarning> | ||
<Image | ||
className="w-12 object-cover" | ||
src={galleryImage.imageUrl} | ||
width={300} | ||
height={200} | ||
alt={`Zdjęcie`} | ||
/> | ||
|
||
<script>document.getElementById("gallery-modal").showModal();</script> | ||
</dialog> | ||
); | ||
} | ||
|
||
export const dynamicParams = false; | ||
|
||
export async function generateStaticParams() { | ||
const recipes = await prisma.recipe.findMany({ | ||
include: { | ||
category: true, | ||
galleryImages: true, | ||
}, | ||
}); | ||
|
||
return ( | ||
recipes.flatMap((recipe) => | ||
recipe.galleryImages?.map((galleryImage) => ({ | ||
categorySlug: recipe.category.slug, | ||
recipeSlug: recipe.slug, | ||
imageId: galleryImage.id.toString(), | ||
})), | ||
) ?? [] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { notFound } from "next/navigation"; | ||
import { prisma } from "@/data"; | ||
import { Recipe } from "@/components/recipe/recipe"; | ||
|
||
interface Params { | ||
categorySlug: string; | ||
recipeSlug: string; | ||
} | ||
|
||
interface Props { | ||
params: Promise<Params>; | ||
children: React.ReactNode; | ||
} | ||
|
||
export default async function Layout({ params, children }: Props) { | ||
const { categorySlug, recipeSlug } = await params; | ||
const category = await prisma.category.findUnique({ | ||
where: { | ||
slug: categorySlug, | ||
}, | ||
}); | ||
|
||
if (!category) { | ||
return notFound(); | ||
} | ||
|
||
const recipe = await prisma.recipe.findUnique({ | ||
where: { | ||
slug: recipeSlug, | ||
}, | ||
include: { | ||
category: true, | ||
instructions: true, | ||
ingredients: true, | ||
galleryImages: true, | ||
}, | ||
}); | ||
|
||
if (!recipe) { | ||
return notFound(); | ||
} | ||
|
||
return ( | ||
<div className="max-w-screen-xl mx-auto"> | ||
<Recipe | ||
title={recipe.title} | ||
coverImage={recipe.coverImage} | ||
coverImageBlurDataUrl={recipe.coverImageBlurDataUrl} | ||
galleryImages={recipe.galleryImages} | ||
slug={recipe.slug} | ||
categorySlug={recipe.category.slug} | ||
ingredients={recipe.ingredients} | ||
instructions={recipe.instructions} | ||
/> | ||
{children} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters