diff --git a/app/components/RecipeDetailCard.jsx b/app/components/RecipeDetailCard.jsx new file mode 100644 index 0000000..77d532b --- /dev/null +++ b/app/components/RecipeDetailCard.jsx @@ -0,0 +1,133 @@ +"use client"; +import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; +import fetchSingleRecipe from "../../api/recipe/[id]/route"; +import React from 'react'; +import RecipeSkeleton from "../../components/RecipeDetailSkeleton"; +import RecipeDetailCard from "@/app/components/RecipeDetailCard"; + + +const formatTime = (minutes) => { + const hours = Math.floor(minutes / 60); + const mins = minutes % 60; + return hours > 0 ? `${hours}h ${mins}m` : `${mins}m`; +}; + +const RecipeDetailCard = ({ params }) => { + const { id } = params; + const [recipe, setRecipe] = useState(null); + const [activeTab, setActiveTab] = useState("ingredients"); + const router = useRouter(); + + useEffect(() => { + const getRecipe = async () => { + const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); + + // Delay for 2 seconds + await delay(4000); + const data = await fetchSingleRecipe(id); + if (data) { + setRecipe(data); + } + }; + getRecipe(); + }, [id])}; + + + + + return ( +
+ Discover how to make this delicious {recipe.name}. Perfect for {recipe.mealType || "any occasion"}. +
+ ++ Prep Time: {formatTime(recipe.prepTimeMinutes)} +
++ Cook Time: {formatTime(recipe.cookTimeMinutes)} +
++ Total Time: {formatTime(totalTime)} +
++ Servings: {recipe.servings} servings +
+