Skip to content

Commit

Permalink
Fix lists by tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ertrzyiks committed Oct 7, 2023
1 parent fecd112 commit c7ff1e7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
24 changes: 14 additions & 10 deletions src/app/[categorySlug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { notFound } from 'next/navigation';
import Link from 'next/link'
import { RecipeListItem } from '@/components/recipe-list-item/recipe-list-item'
import { RecipeList } from '@/components/recipe-list/recipe-list'
import { prisma } from '@/data'

interface Params {
Expand Down Expand Up @@ -31,15 +32,18 @@ export default async function Page({ params }: Props) {
})

return (
<main className="flex flex-col items-center">

{recipes.map((recipe) => (
<div key={recipe.id} className="flex place-items-center">
<Link href={`/${recipe.category.slug}/${recipe.slug}`}>
{recipe.title}
</Link>
</div>
))}
<main className="w-full">
<h2 className="text-2xl my-8">Przepisy w kategorii {category.title}</h2>
<RecipeList>
{recipes.map((recipe) => (
<RecipeListItem
key={recipe.id}
href={`/${recipe.category.slug}/${recipe.slug}`}
coverImage={recipe.coverImage}
title={recipe.title}
/>
))}
</RecipeList>
</main >
)
}
Expand Down
54 changes: 54 additions & 0 deletions src/app/tag/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { notFound } from 'next/navigation'
import { prisma } from '@/data'
import { RecipeListItem } from '@/components/recipe-list-item/recipe-list-item'
import { RecipeList } from '@/components/recipe-list/recipe-list'

interface Params {
slug: string
}

interface Props {
params: Params
}

export default async function Page({ params }: Props) {
const tag = await prisma.tag.findUnique({
where: {
slug: params.slug
}
})

if (!tag) {
return notFound()
}

const recipes = await prisma.recipe.findMany({
where: {
tags: {
some: {
id: tag.id
}
}
},
include: {
category: true,
}
})

return (
<main className="w-full">
<h2 className="text-2xl my-8">Przepisy w kategorii {tag.title}</h2>

<RecipeList>
{recipes.map((recipe) => (
<RecipeListItem
key={recipe.id}
href={`/${recipe.category.slug}/${recipe.slug}`}
coverImage={recipe.coverImage}
title={recipe.title}
/>
))}
</RecipeList>
</main >
)
}
11 changes: 0 additions & 11 deletions src/app/tag/[tagId]/page.tsx

This file was deleted.

0 comments on commit c7ff1e7

Please sign in to comment.