-
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.
Merge pull request #109 from yummy-recipes/implement-gallery
Implement gallery
- Loading branch information
Showing
11 changed files
with
244 additions
and
51 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
prisma/migrations/20250107194418_add_gallery_images/migration.sql
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,9 @@ | ||
-- CreateTable | ||
CREATE TABLE "RecipeGalleryImage" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"recipeId" INTEGER NOT NULL, | ||
"imageUrl" TEXT NOT NULL, | ||
"blurDataUrl" TEXT, | ||
"position" INTEGER NOT NULL, | ||
CONSTRAINT "RecipeGalleryImage_recipeId_fkey" FOREIGN KEY ("recipeId") REFERENCES "Recipe" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
# It should be added in your version-control system (e.g., Git) | ||
provider = "sqlite" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use client"; | ||
|
||
import { Dialog, DialogPanel } from "@headlessui/react"; | ||
import { redirect } from "next/navigation"; | ||
|
||
interface Props { | ||
categorySlug: string; | ||
recipeSlug: string; | ||
children: React.ReactNode; | ||
} | ||
export function GalleryDialog({ categorySlug, recipeSlug, children }: Props) { | ||
const handleClose = () => { | ||
redirect(`/${categorySlug}/${recipeSlug}`); | ||
}; | ||
|
||
return ( | ||
<Dialog open onClose={handleClose} className="relative z-50"> | ||
{/* The backdrop, rendered as a fixed sibling to the panel container */} | ||
<div className="fixed inset-0 bg-black/30" aria-hidden="true" /> | ||
<div className="fixed inset-0 flex w-screen items-center justify-center p-4"> | ||
<DialogPanel className="w-full max-w-sm rounded bg-white"> | ||
{children} | ||
</DialogPanel> | ||
</div> | ||
</Dialog> | ||
); | ||
} |
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"; | ||
import { GalleryDialog } from "./dialog"; | ||
|
||
interface Params { | ||
categorySlug: string; | ||
recipeSlug: string; | ||
imageId: string; | ||
} | ||
|
||
interface Props { | ||
params: Promise<Params>; | ||
} | ||
export default async function Page({ params }: Props) { | ||
const { categorySlug, recipeSlug, imageId } = await params; | ||
|
||
const galleryImage = await prisma.recipeGalleryImage.findUnique({ | ||
where: { | ||
id: parseInt(imageId), | ||
}, | ||
}); | ||
|
||
if (!galleryImage) { | ||
return notFound(); | ||
} | ||
|
||
return ( | ||
<GalleryDialog categorySlug={categorySlug} recipeSlug={recipeSlug}> | ||
<Image | ||
className="w-full object-cover" | ||
src={galleryImage.imageUrl} | ||
width={600} | ||
height={400} | ||
alt={`Zdjęcie`} | ||
/> | ||
</GalleryDialog> | ||
); | ||
} | ||
|
||
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
Oops, something went wrong.