mirror of
				https://github.com/DerTyp7/explainegy-nextjs.git
				synced 2025-10-30 21:27:12 +01:00 
			
		
		
		
	add api
This commit is contained in:
		| @@ -4,32 +4,30 @@ import "../styles/variables.scss"; | ||||
| import Nav from "./Nav"; | ||||
| import Footer from "./Footer"; | ||||
| import { Category } from "@prisma/client"; | ||||
| import prisma from "../lib/prisma"; | ||||
| import { NavCategory } from "./Nav"; | ||||
| import urlJoin from "url-join"; | ||||
| import { apiUrl } from "./global"; | ||||
|  | ||||
| export async function GetNavCategories(): Promise<NavCategory[]> { | ||||
| 	const result: NavCategory[] = await prisma.category.findMany({ | ||||
| 		select: { name: true, title: true }, | ||||
| 	}); | ||||
| 	return result; | ||||
| async function getCategories(): Promise<Category[]> { | ||||
|   const result: Response = await fetch(urlJoin(apiUrl, `categories`), { | ||||
|     cache: "force-cache", | ||||
|     next: { revalidate: 3600 }, | ||||
|   }); | ||||
|  | ||||
|   return await result.json(); | ||||
| } | ||||
|  | ||||
| export default async function RootLayout({ | ||||
| 	children, | ||||
| }: { | ||||
| 	children: React.ReactNode; | ||||
| }) { | ||||
| 	return ( | ||||
| 		<html style={{ scrollBehavior: "smooth" }}> | ||||
| 			<head></head> | ||||
| export default async function RootLayout({ children }: { children: React.ReactNode }) { | ||||
|   return ( | ||||
|     <html style={{ scrollBehavior: "smooth" }}> | ||||
|       <head></head> | ||||
|  | ||||
| 			<body className="body"> | ||||
| 				<header> | ||||
| 					<Nav categories={await GetNavCategories()} /> | ||||
| 				</header> | ||||
| 				<main>{children}</main> | ||||
| 				<Footer /> | ||||
| 			</body> | ||||
| 		</html> | ||||
| 	); | ||||
|       <body className="body"> | ||||
|         <header> | ||||
|           <Nav categories={await getCategories()} /> | ||||
|         </header> | ||||
|         <main>{children}</main> | ||||
|         <Footer /> | ||||
|       </body> | ||||
|     </html> | ||||
|   ); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Janis
					Janis