-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Recipe For The Day Suggestion section (#444)
* FEATURE: Recipe For The Day Suggestion section Fixes #328 * Update Landing.jsx * Update Landing.jsx * Update Landing.jsx * Update Landing.jsx * Update RecipeController.js * Update RecipeController.js --------- Co-authored-by: Alfiya Siddique <[email protected]>
- Loading branch information
1 parent
91a82be
commit dd70aba
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import axios from 'axios'; | ||
import Cards from './Cards'; // Import the Cards component to display the recipe | ||
|
||
const RecipeOfTheDay = () => { | ||
const [recipe, setRecipe] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(null); | ||
const backendURL = import.meta.env.VITE_BACKEND_URL; | ||
|
||
useEffect(() => { | ||
const fetchRecipeOfTheDay = async () => { | ||
try { | ||
const response = await axios.get(`${backendURL}/api/recipes/random`); | ||
setRecipe(response.data.recipe); // Assuming the API returns a recipe object | ||
} catch (error) { | ||
console.error('Error fetching recipe of the day:', error); | ||
setError('Failed to fetch recipe. Please try again later.'); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchRecipeOfTheDay(); | ||
}, []); // No dependencies needed | ||
|
||
return ( | ||
<section id="RecipeOfTheDay" className="py-4 my-20 mx-8"> | ||
<h1 className="text-center font-semibold text-4xl text-red-700 my-4 font-[Merriweather]"> | ||
Recipe For The Day | ||
</h1> | ||
{loading ? ( | ||
<div className="flex justify-center items-center py-10"> | ||
<div className="animate-spin rounded-full h-16 w-16 border-t-2 border-red-700"></div> | ||
</div> | ||
) : error ? ( | ||
<p className="text-center text-red-500">{error}</p> | ||
) : ( | ||
<Cards dish={recipe} /> | ||
)} | ||
</section> | ||
); | ||
}; | ||
|
||
export default RecipeOfTheDay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters