2025-07-08 10:40:49 -07:00
|
|
|
import RecipeCard from "../components/RecipeCard.tsx"
|
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
import { useState, useEffect } from "react";
|
2025-07-08 15:42:28 -07:00
|
|
|
import { getRecipeById } from "../services/frontendApi.js";
|
2025-07-08 10:40:49 -07:00
|
|
|
import { type Recipe } from "../types/Recipe"
|
|
|
|
|
|
|
|
function RecipePage() {
|
|
|
|
const [recipe, setRecipe] = useState<Recipe>({});
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
const { id } = useParams();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const loadRecipe = async () => {
|
|
|
|
try {
|
|
|
|
const recipe = await getRecipeById(id);
|
|
|
|
setRecipe(recipe);
|
|
|
|
console.log(recipe)
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
setError("Failed to load recipes...");
|
|
|
|
} finally {
|
|
|
|
setLoading(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
loadRecipe();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="recipe">
|
|
|
|
|
|
|
|
{error && <div className="error-message">{error}</div>}
|
|
|
|
|
|
|
|
{loading ? (
|
|
|
|
<div className="loading">Loading...</div>
|
|
|
|
) : (
|
|
|
|
<div className="recipe-card">
|
|
|
|
<RecipeCard recipe={recipe} key={recipe.id} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RecipePage;
|