import styles from "../../../styles/Category.module.scss"; import Link from "next/link"; import prisma from "../../../lib/prisma"; import { Article, Category } from "@prisma/client"; export async function GetAllArticles(category: Category): Promise { return await prisma.article.findMany({ where: { category: category } }); } export async function GetPopularArticles( category: Category ): Promise { return await prisma.article.findMany({ where: { category: category }, take: 6, }); } export async function GetRecentArticles( category: Category ): Promise { return await prisma.article.findMany({ where: { category: category }, take: 6, orderBy: { dateCreated: "desc" }, }); } export async function GetCategory(categoryName: string): Promise { return await prisma.category.findUnique({ where: { name: categoryName } }); } export default async function CategoryPage({ params, }: { params: { categoryName: string }; }) { const categoryName = params.categoryName.toLowerCase().replaceAll("%20", " "); const category: Category = await GetCategory(categoryName); const allArticles: Article[] = await GetAllArticles(category); const popularArticles: Article[] = await GetPopularArticles(category); const recentArticles: Article[] = await GetRecentArticles(category); return (

{category?.title}

Most popular articles

{popularArticles?.map((a, i) => { { return ( {a.name} ); } })}
{/*

Most recent articles

{recentArticles?.map((a, i) => { { return ( {a.name} ); } })}
*/}

All articles

{allArticles?.map((a, i) => { { return ( {a.name} ); } })}
); }