ingredients and steps on recipe page
This commit is contained in:
parent
5898ac7779
commit
925135d08c
4 changed files with 43 additions and 12 deletions
|
@ -33,7 +33,7 @@ app.get("/recipe/:id", async (req, res) => {
|
||||||
const [recipe, ingredients, steps] = await Promise.all([recipeQuery, ingredientsQuery, stepsQuery]);
|
const [recipe, ingredients, steps] = await Promise.all([recipeQuery, ingredientsQuery, stepsQuery]);
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
recipe: recipe[0],
|
details: recipe[0],
|
||||||
ingredients: ingredients.map(ingredient => ({
|
ingredients: ingredients.map(ingredient => ({
|
||||||
name: ingredient.name,
|
name: ingredient.name,
|
||||||
quantity: ingredient.quantity,
|
quantity: ingredient.quantity,
|
||||||
|
|
|
@ -1,11 +1,23 @@
|
||||||
import { type Recipe } from "../types/Recipe"
|
import { type Recipe, type Ingredient } from "../types/Recipe"
|
||||||
|
|
||||||
function RecipeCard({ recipe }: { recipe: Recipe }) {
|
function RecipeCard({ recipe }: { recipe: Recipe }) {
|
||||||
return (
|
return (
|
||||||
<div className="recipe-card">
|
<div className="recipe-card">
|
||||||
<div className="recipe-info">
|
<div className="recipe-info">
|
||||||
<h3>{recipe.name}</h3>
|
<h3>{recipe.details.name}</h3>
|
||||||
<p>{recipe.cuisine}</p>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,7 +5,11 @@ import { getRecipeById } from "../services/frontendApi.js";
|
||||||
import { type Recipe } from "../types/Recipe"
|
import { type Recipe } from "../types/Recipe"
|
||||||
|
|
||||||
function RecipePage() {
|
function RecipePage() {
|
||||||
const [recipe, setRecipe] = useState<Recipe>({});
|
const [recipe, setRecipe] = useState<Recipe>({
|
||||||
|
details: {},
|
||||||
|
ingredients: [],
|
||||||
|
steps: {}
|
||||||
|
});
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
@ -24,7 +28,7 @@ function RecipePage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadRecipe();
|
loadRecipe();
|
||||||
}, []);
|
}, [id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="recipe">
|
<div className="recipe">
|
||||||
|
@ -35,7 +39,7 @@ function RecipePage() {
|
||||||
<div className="loading">Loading...</div>
|
<div className="loading">Loading...</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="recipe-card">
|
<div className="recipe-card">
|
||||||
<RecipeCard recipe={recipe} key={recipe.id} />
|
<RecipeCard recipe={recipe} key={recipe.details.id} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,22 @@
|
||||||
|
interface Step {
|
||||||
|
[key: string]: string;
|
||||||
|
// [index: number]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Ingredient {
|
||||||
|
name: string;
|
||||||
|
quantity: number;
|
||||||
|
unit: string;
|
||||||
|
}
|
||||||
interface Recipe {
|
interface Recipe {
|
||||||
|
details: {
|
||||||
id?: number;
|
id?: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
cuisine?: string;
|
cuisine?: string;
|
||||||
|
},
|
||||||
|
ingredients: Ingredient[],
|
||||||
|
steps?: Step;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { Recipe }
|
|
||||||
|
export type { Recipe, Ingredient, Step }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue