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 ( +
+ + + + +
+
+ {recipe.name} +
+ +
+ +

+ {recipe.name} +

+ + +

+ 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 +

+
+ + +
    +
  • setActiveTab("ingredients")} + > + Ingredients +
  • +
  • setActiveTab("instructions")} + > + Instructions +
  • +
+ + +
+ {activeTab === "ingredients" ? ( +
+

Ingredients

+
    + {recipe.ingredients.map((ingredient, index) => ( +
  • {ingredient}
  • + ))} +
+
+ ) : ( +
+

Instructions

+
    + {recipe.instructions.map((instruction, index) => ( +
  • {instruction}
  • + ))} +
+
+ )} +
+
+
+
+ ); + + +export default RecipeDetailCard; \ No newline at end of file diff --git a/app/components/RecipeGrid.jsx b/app/components/RecipeGrid.jsx index eaf497f..0208baa 100644 --- a/app/components/RecipeGrid.jsx +++ b/app/components/RecipeGrid.jsx @@ -1,6 +1,7 @@ "use client" import React, { useEffect, useState } from 'react'; import RecipeCard from './RecipeCard'; // Update this import +import SkeletonGrid from './SkeletonMain'; const RecipeGrid = () => { const [recipes, setRecipes] = useState(null); diff --git a/app/recipes/[id]/page.jsx b/app/recipes/[id]/page.jsx index c0bad77..e2f524d 100644 --- a/app/recipes/[id]/page.jsx +++ b/app/recipes/[id]/page.jsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import fetchSingleRecipe from "../../api/recipe/[id]/route"; -import RecipeSkeleton from "@/app/components/RecipeDetailSkeleton"; +import RecipeSkeleton from "../../components/RecipeDetailSkeleton"; const formatTime = (minutes) => {