diff --git a/src/App.js b/src/App.js index bbadedc..efe0a13 100644 --- a/src/App.js +++ b/src/App.js @@ -47,20 +47,19 @@ import SymptomAssessment from "./routes/SymptomAssessment/SymptomAssessment"; import Leaderboard from "./routes/LeaderBoard/leaderBoard"; import ObesityPredictor from "./routes/survey/ObesityPredictor"; import Predictionresult from "./routes/survey/predictionresult"; -import UiTimer from "./routes/UiTimer/UiTimer" -import Settings from "./routes/Settings/Settings" +import UiTimer from "./routes/UiTimer/UiTimer"; +import Settings from "./routes/Settings/Settings"; import HealthFAQ from "./routes/HealthFAQ/HealthFAQ"; -import FitnessRoadmap from './routes/survey/FitnessRoadmap'; +import FitnessRoadmap from "./routes/survey/FitnessRoadmap"; import Community from "./routes/Community/Community"; import PostDetail from "./routes/Community/PostDetail"; import ScanBarcode from "./routes/ScanBarcode/ScanBarcode"; import AuthCallback from "./pages/AuthCallback"; -import DailyPlanEdit from './routes/DailyPlan/DailyPlanEdit'; +import DailyPlanEdit from "./routes/DailyPlan/DailyPlanEdit"; function App() { const { currentUser } = useContext(UserContext); - - + // Initialize font size settings for elderly users useEffect(() => { initializeFontSize(); @@ -87,7 +86,7 @@ function App() { } /> } /> } /> - }/> + } /> } /> {/* Private Routes */} @@ -99,14 +98,7 @@ function App() { } /> - - - - } - /> + } /> } /> - - - - } - /> + } /> } /> - - - } + path="settings" + element={ + + + + } /> { return ( {/* Close Button */} - × {/* This renders a nice cross */} @@ -34,15 +34,31 @@ const SideMenu = ({ isOpen, toggleMenu }) => { {currentUser ? ( <> - Home - Menu - Meal Planning - Edit Daily Plan - Health News - Fitness Roadmap - Community + + Home + + + Menu + + + Meal Planning + + + Edit Daily Plan + + + Health News + + + Fitness Roadmap + + + Community + - HealthFAQ + + HealthFAQ + {/* Recipes Dropdown */} @@ -54,10 +70,21 @@ const SideMenu = ({ isOpen, toggleMenu }) => { {openDropdown === "recipes" && ( - Create Recipe - Search Recipes - Recipe Rating - UiTimer + + Create Recipe + + + Search Recipes + + + Recipe + + + Recipe Rating + + + UiTimer + )} @@ -72,19 +99,42 @@ const SideMenu = ({ isOpen, toggleMenu }) => { {openDropdown === "user" && ( - Dietary Preference - Profile + + Dietary Preference + + + Profile + )} - Scan Products - Scan Barcode - Allergies & Intolerances - Symptom Assessment - Health Tools - Settings - { logOut(); toggleMenu(); }}>Log Out + + Scan Products + + + Scan Barcode + + + Allergies & Intolerances + + + Symptom Assessment + + + Health Tools + + + Settings + + { + logOut(); + toggleMenu(); + }} + > + Log Out + > @@ -96,13 +146,27 @@ const SideMenu = ({ isOpen, toggleMenu }) => { Create Account */} - Home - Menu - Meal Planning - Edit Daily Plan - Health News - Fitness Roadmap - Community + + Home + + + Menu + + + Meal Planning + + + Edit Daily Plan + + + Health News + + + Fitness Roadmap + + + Community + {/* Recipes Dropdown */} @@ -114,11 +178,21 @@ const SideMenu = ({ isOpen, toggleMenu }) => { {openDropdown === "recipes" && ( - Create Recipe - Search Recipes - Recipe Rating - UiTimer - HealthFAQ + + Create Recipe + + + Search Recipes + + + Recipe Rating + + + UiTimer + + + HealthFAQ + )} @@ -133,19 +207,42 @@ const SideMenu = ({ isOpen, toggleMenu }) => { {openDropdown === "user" && ( - Dietary Preference - Profile + + Dietary Preference + + + Profile + )} - Scan Products - Scan Barcode - Allergies & Intolerances - Symptom Assessment - Health Tools - Settings - { logOut(); toggleMenu(); }}>Log Out + + Scan Products + + + Scan Barcode + + + Allergies & Intolerances + + + Symptom Assessment + + + Health Tools + + + Settings + + { + logOut(); + toggleMenu(); + }} + > + Log Out + > diff --git a/src/routes/CreateRecipe/data/db/db.js b/src/routes/CreateRecipe/data/db/db.js index 5f71fbb..734b7e8 100644 --- a/src/routes/CreateRecipe/data/db/db.js +++ b/src/routes/CreateRecipe/data/db/db.js @@ -24,3 +24,16 @@ export const getRecipes = async () => { console.log("Fetched from IDB:", all); // Add this line return all; }; + +export const deleteRecipe = async (id) => { + try { + const db = await initDB(); + const tx = db.transaction("recipes", "readwrite"); + const store = tx.objectStore("recipes"); + await store.delete(id); + await tx.done; + console.log(`Recipe with ID ${id} deleted successfully.`); + } catch (error) { + console.error("Error deleting recipe:", error); + } +}; diff --git a/src/routes/RecipeRating/RecipeDetail.js b/src/routes/RecipeRating/RecipeDetail.js index 5ca76ec..85ea210 100644 --- a/src/routes/RecipeRating/RecipeDetail.js +++ b/src/routes/RecipeRating/RecipeDetail.js @@ -1,26 +1,36 @@ import { Star } from "lucide-react"; -import { useParams } from "react-router-dom"; +import { useParams, useNavigate } from "react-router-dom"; import { useEffect, useState } from "react"; -import { getRecipes } from "../../routes/CreateRecipe/data/db/db"; +import { getRecipes, deleteRecipe } from "../../routes/CreateRecipe/data/db/db"; export default function CreamySalad() { const rating = 3; // out of 5 const [recipe, setRecipe] = useState(null); - + const navigate = useNavigate(); // <-- Initialize useNavigate const { id } = useParams(); // <-- get ID from URL useEffect(() => { const fetchData = async () => { const data = await getRecipes(); - - // find the recipe that matches the id from URL const recipe = data.find((item) => String(item.id) === String(id)); - - setRecipe(recipe); // now recipes holds only the matching one + setRecipe(recipe); }; fetchData(); - }, [id]); // depend on id + }, [id]); + + // New function to handle recipe deletion + // In CreamySalad.jsx + + // Inside the handleDelete function + const handleDelete = async () => { + try { + await deleteRecipe(Number(id)); // Convert the ID to a number + navigate("/recipe"); + } catch (error) { + console.error("Failed to delete recipe:", error); + } + }; if (!recipe) return Loading...; @@ -200,22 +210,23 @@ export default function CreamySalad() { Delete
Loading...