recipes.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import Layout from "@/components/Layout";
  2. import { GetStaticProps, InferGetStaticPropsType } from "next";
  3. import { Recipe } from "types/recipes";
  4. import { Subtitle } from 'components/Typography';
  5. import RecipeItem from "components/RecipeItem";
  6. import { TextInput } from "@/components/Forms";
  7. import { Button } from "@/components/Button";
  8. export const getStaticProps = async () => {
  9. const res = await fetch("http://localhost:3000/recipes/all/");
  10. const recipeList: Recipe[] = await res.json();
  11. return {
  12. props: {
  13. recipeList,
  14. },
  15. };
  16. };
  17. const Recipes = ({
  18. recipeList = [],
  19. }: InferGetStaticPropsType<typeof getStaticProps>) => {
  20. return (
  21. <Layout>
  22. <div>
  23. <TextInput placeholder='search' id='recipe-search' />
  24. </div>
  25. <div>
  26. <Subtitle>Favorites</Subtitle>
  27. </div>
  28. <div>
  29. <Subtitle>All</Subtitle>
  30. {recipeList.map((recipe, index) => (
  31. <RecipeItem recipe={recipe} key={index} onClick={() => console.log(recipe.name)} />
  32. ))}
  33. </div>
  34. </Layout>
  35. );
  36. };
  37. export default Recipes;