From 6f4c34166e17bfb87146d9ff2ebea56decf5fc23 Mon Sep 17 00:00:00 2001 From: Aditi Verma Date: Fri, 25 Oct 2024 22:33:37 +0530 Subject: [PATCH 1/5] Create RecipeOfTheDay.jsx --- frontend/src/Components/RecipeOfTheDay.jsx | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 frontend/src/Components/RecipeOfTheDay.jsx diff --git a/frontend/src/Components/RecipeOfTheDay.jsx b/frontend/src/Components/RecipeOfTheDay.jsx new file mode 100644 index 00000000..aa7ad138 --- /dev/null +++ b/frontend/src/Components/RecipeOfTheDay.jsx @@ -0,0 +1,33 @@ +// src/components/RecipeOfTheDay.jsx +import React, { useEffect, useState } from 'react'; + +function RecipeOfTheDay() { + const [recipe, setRecipe] = useState(null); + + useEffect(() => { + // Fetch a random recipe from the API + fetch('/api/recipes/random') + .then((response) => response.json()) + .then((data) => setRecipe(data)) + .catch((error) => console.error('Error fetching recipe:', error)); + }, []); + + if (!recipe) return

Loading Recipe of the Day...

; + + return ( +
+

Recipe of the Day

+
+

{recipe.title}

+

{recipe.description}

+ {recipe.title} +
+
+ ); +} + +export default RecipeOfTheDay; From e35ecabbdcfe37d67f3ced2519f471b129539bf2 Mon Sep 17 00:00:00 2001 From: Aditi Verma Date: Fri, 25 Oct 2024 22:40:27 +0530 Subject: [PATCH 2/5] Update App.jsx --- frontend/src/App.jsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 3b664c2c..13f0ee18 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,6 +1,5 @@ // eslint-disable-next-line no-unused-vars -import React from "react"; -import { useState, useEffect } from "react"; +import React, { useState, useEffect } from "react"; import { BrowserRouter, Route, Routes } from "react-router-dom"; import "./App.css"; import Navbar from "./Components/Navbar.jsx"; @@ -20,6 +19,7 @@ import Contributors from "./Pages/Contributors.jsx"; // Import the Contributors import PrivacyPolicy from "./Components/PrivacyPolicy.jsx"; import NotFound from "./Pages/NotFound.jsx"; import RecipeSuggestions from "./Pages/RecipeSuggestions.jsx"; +import RecipeOfTheDay from "./Components/RecipeOfTheDay.jsx"; // Import RecipeOfTheDay component function App() { const [showScroll, setShowScroll] = useState(false); @@ -82,10 +82,12 @@ function App() { } /> } /> } /> - {/* Add Contributors route */} } /> - {/* Added Privacy-policy route */} + + {/* Add Recipe of the Day section on the homepage */} + } /> +