ingredients and steps on recipe page
This commit is contained in:
parent
5898ac7779
commit
925135d08c
4 changed files with 43 additions and 12 deletions
|
@ -1,11 +1,23 @@
|
|||
import { type Recipe } from "../types/Recipe"
|
||||
import { type Recipe, type Ingredient } from "../types/Recipe"
|
||||
|
||||
function RecipeCard({ recipe }: { recipe: Recipe }) {
|
||||
return (
|
||||
<div className="recipe-card">
|
||||
<div className="recipe-info">
|
||||
<h3>{recipe.name}</h3>
|
||||
<p>{recipe.cuisine}</p>
|
||||
<h3>{recipe.details.name}</h3>
|
||||
<p>{recipe.details.cuisine}</p>
|
||||
<h4>Ingredients:</h4>
|
||||
<ul>
|
||||
{recipe.ingredients.map((ingredient: Ingredient, index) => (
|
||||
<li key={index}>{ingredient.name} {ingredient.quantity} {ingredient.unit}</li>
|
||||
))}
|
||||
</ul>
|
||||
<h4>Steps:</h4>
|
||||
<ol>
|
||||
{recipe.steps && Object.keys(recipe.steps || {}).map((stepNumber) => (
|
||||
<li key={stepNumber}>{recipe.steps?.[parseInt(stepNumber)]}</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -5,7 +5,11 @@ import { getRecipeById } from "../services/frontendApi.js";
|
|||
import { type Recipe } from "../types/Recipe"
|
||||
|
||||
function RecipePage() {
|
||||
const [recipe, setRecipe] = useState<Recipe>({});
|
||||
const [recipe, setRecipe] = useState<Recipe>({
|
||||
details: {},
|
||||
ingredients: [],
|
||||
steps: {}
|
||||
});
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const { id } = useParams();
|
||||
|
@ -24,7 +28,7 @@ function RecipePage() {
|
|||
}
|
||||
};
|
||||
loadRecipe();
|
||||
}, []);
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<div className="recipe">
|
||||
|
@ -35,7 +39,7 @@ function RecipePage() {
|
|||
<div className="loading">Loading...</div>
|
||||
) : (
|
||||
<div className="recipe-card">
|
||||
<RecipeCard recipe={recipe} key={recipe.id} />
|
||||
<RecipeCard recipe={recipe} key={recipe.details.id} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
interface Recipe {
|
||||
id?: number;
|
||||
name?: string;
|
||||
cuisine?: string;
|
||||
interface Step {
|
||||
[key: string]: string;
|
||||
// [index: number]: string;
|
||||
}
|
||||
|
||||
export type { Recipe }
|
||||
interface Ingredient {
|
||||
name: string;
|
||||
quantity: number;
|
||||
unit: string;
|
||||
}
|
||||
interface Recipe {
|
||||
details: {
|
||||
id?: number;
|
||||
name?: string;
|
||||
cuisine?: string;
|
||||
},
|
||||
ingredients: Ingredient[],
|
||||
steps?: Step;
|
||||
}
|
||||
|
||||
|
||||
export type { Recipe, Ingredient, Step }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue