recipes.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Layout from "@/components/Layout";
  2. import { GetStaticProps, InferGetStaticPropsType } from "next";
  3. import { getAllRecipes, getAllTags } from '@/utils/api';
  4. import Header from '@/components/Layout/Header';
  5. import Container from '@/components/Layout/Container';
  6. import { Subtitle } from 'components/Typography';
  7. import RecipeItem from "components/RecipeItem";
  8. import { TextInput, ChipGroup, Chip } from "@/components/Forms";
  9. export const getStaticProps = async () => {
  10. const recipeList = await getAllRecipes();
  11. const tags = await getAllTags();
  12. return {
  13. props: {
  14. recipeList,
  15. tags: tags.map(tag => tag.name),
  16. },
  17. };
  18. };
  19. const Recipes = ({
  20. recipeList = [],
  21. tags
  22. }: InferGetStaticPropsType<typeof getStaticProps>) => {
  23. return (
  24. <Layout>
  25. <Header>
  26. <TextInput placeholder='search' id='recipe-search' />
  27. <ChipGroup>
  28. {tags.map(tag => (
  29. <Chip key={tag} label={tag} color='primary' />
  30. ))}
  31. </ChipGroup>
  32. </Header>
  33. <Container>
  34. <Subtitle>Favorites</Subtitle>
  35. </Container>
  36. <Container>
  37. <Subtitle>All</Subtitle>
  38. {recipeList.map((recipe, index) => (
  39. <RecipeItem recipe={recipe} key={index} onClick={() => console.log(recipe.name)} />
  40. ))}
  41. </Container>
  42. </Layout>
  43. );
  44. };
  45. export default Recipes;