1 | import React from "react";
|
---|
2 | import styles from "../../css/HomeCss/featuredRecipes.module.css";
|
---|
3 | import { useNavigate } from "react-router-dom";
|
---|
4 |
|
---|
5 | function FeaturedRecipes() {
|
---|
6 | const navigate = useNavigate();
|
---|
7 |
|
---|
8 | const handleRedirect = (event) => {
|
---|
9 | const url = event.currentTarget.querySelector('img').getAttribute("alt");
|
---|
10 | if (url) {
|
---|
11 | navigate(url, {
|
---|
12 | state: {
|
---|
13 | fromHomepage: true
|
---|
14 | },
|
---|
15 | });
|
---|
16 | }
|
---|
17 | };
|
---|
18 |
|
---|
19 | return (
|
---|
20 | <section className={styles.featuredRecipes}>
|
---|
21 | <div className={styles.container}>
|
---|
22 | <h2 className={styles.sectionTitle}>Featured Recipes</h2>
|
---|
23 | <div className={styles.recipeCards}>
|
---|
24 | <div className={styles.recipeCard} onClick={handleRedirect}>
|
---|
25 | <img
|
---|
26 | src="https://www.themealdb.com/images/media/meals/sywswr1511383814.jpg"
|
---|
27 | alt="/recipes/83"
|
---|
28 | />
|
---|
29 | <div className={styles.recipeInfo}>
|
---|
30 | <h3 className={styles.recipeTitle}>Banana Pancakes</h3>
|
---|
31 | <p>A delightful breakfast option.</p>
|
---|
32 | <div className={styles.rating}>4.5 ★</div>
|
---|
33 | </div>
|
---|
34 | </div>
|
---|
35 | <div className={styles.recipeCard} onClick={handleRedirect}>
|
---|
36 | <img
|
---|
37 | src="https://www.themealdb.com/images/media/meals/tqtywx1468317395.jpg"
|
---|
38 | alt="/recipes/12"
|
---|
39 | />
|
---|
40 | <div className={styles.recipeInfo}>
|
---|
41 | <h3 className={styles.recipeTitle}>Chocolate Gateau</h3>
|
---|
42 | <p>Rich and light chocolate indulgence.</p>
|
---|
43 | <div className={styles.rating}>4.8 ★</div>
|
---|
44 | </div>
|
---|
45 | </div>
|
---|
46 | </div>
|
---|
47 | </div>
|
---|
48 | </section>
|
---|
49 | );
|
---|
50 | }
|
---|
51 |
|
---|
52 | export default FeaturedRecipes;
|
---|