recipes.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. export const getStaticProps = async () => {
  8. const res = await fetch("http://localhost:3000/recipes/all/");
  9. const recipeList: Recipe[] = await res.json();
  10. return {
  11. props: {
  12. recipeList,
  13. },
  14. };
  15. };
  16. const Recipes = ({
  17. recipeList = [],
  18. }: InferGetStaticPropsType<typeof getStaticProps>) => {
  19. return (
  20. <Layout>
  21. <div>
  22. <TextInput placeholder='search' id='recipe-search' />
  23. </div>
  24. <div>
  25. <Subtitle>Favorites</Subtitle>
  26. </div>
  27. <div>
  28. <Subtitle>All</Subtitle>
  29. {recipeList.map((recipe, index) => (
  30. <RecipeItem recipe={recipe} key={index} onClick={() => console.log(recipe.name)} />
  31. ))}
  32. </div>
  33. </Layout>
  34. );
  35. };
  36. export default Recipes;