|
|
@@ -3,10 +3,12 @@ import { GetStaticProps, InferGetStaticPropsType } from "next";
|
|
|
import { getAllRecipes, getAllTags } from '@/utils/api';
|
|
|
import Header from '@/components/Layout/Header';
|
|
|
import Container from '@/components/Layout/Container';
|
|
|
+import { useRouter } from 'next/router';
|
|
|
|
|
|
import { Subtitle } from 'components/Typography';
|
|
|
import RecipeItem from "components/RecipeItem";
|
|
|
import { TextInput, ChipGroup, Chip } from "@/components/Forms";
|
|
|
+import { MouseEventHandler } from "react";
|
|
|
|
|
|
|
|
|
export const getStaticProps = async () => {
|
|
|
@@ -24,6 +26,12 @@ const Recipes = ({
|
|
|
recipeList = [],
|
|
|
tags
|
|
|
}: InferGetStaticPropsType<typeof getStaticProps>) => {
|
|
|
+ const router = useRouter();
|
|
|
+ const openRecipe: (id: string) => MouseEventHandler<Element> = (id) => (e) => {
|
|
|
+ e.preventDefault();
|
|
|
+ router.push(`/recipes/${id}`);
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<Layout>
|
|
|
<Header>
|
|
|
@@ -39,8 +47,8 @@ const Recipes = ({
|
|
|
</Container>
|
|
|
<Container>
|
|
|
<Subtitle>All</Subtitle>
|
|
|
- {recipeList.map((recipe, index) => (
|
|
|
- <RecipeItem recipe={recipe} key={index} onClick={() => console.log(recipe.name)} />
|
|
|
+ {recipeList.map((recipe) => (
|
|
|
+ <RecipeItem recipe={recipe} key={recipe._id} onClick={openRecipe(recipe._id)} />
|
|
|
))}
|
|
|
</Container>
|
|
|
</Layout>
|