-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspecificdish.html
More file actions
126 lines (115 loc) · 5.63 KB
/
Copy pathspecificdish.html
File metadata and controls
126 lines (115 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pink Pau</title>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
<script src="components/header.js" type="text/javascript" defer></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-..." crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header-component></header-component>
<div>
<div id="meals"></div>
<div id="mealDetails" class="meal"></div>
<script>
// Function to get the query parameter
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
const query = getQueryParameter('meal_id');
// Function to fetch meal details
async function fetchMealDetails(mealId) {
const url = `https://www.themealdb.com/api/json/v1/1/lookup.php?i=${mealId}`;
try {
const response = await fetch(url);
const data = await response.json();
displayMeal(data.meals[0]);
} catch (error) {
console.error('Error fetching meal details:', error);
document.getElementById('mealDetails').innerHTML = `<p>Error fetching meal details: ${error}</p>`;
}
}
// Function to display the meal details
function displayMeal(meal) {
const mealDiv = document.getElementById('mealDetails');
if (meal) {
mealDiv.innerHTML = `
<div class= "container">
<div class="container mt-2">
<div class="d-flex justify-content-start">
<a href="dishes.html" class="btn px-4 back-btn" role="button">Back</a>
</div>
</div>
<div class="container center d-flex justify-content-center align-items-center mt-5">
<div class="row">
<h1>${meal.strMeal}</h1>
</div>
</div>
<div class="container d-flex justify-content-center align-items-center mt-5">
<div class="row justify-content-center align-items-center">
<div class="col-8 col-xl-8 ">
<img class="img-fluid" src="${meal.strMealThumb}" alt="${meal.strMeal}">
</div>
</div>
</div>
<div class="container p-5 recipe-content">
<div class="container d-flex row align-items-start mt-5">
<div class="col-6">
<h4>Course</h4>
<p>${meal.strCategory}</p>
</div>
<div class="col-6">
<h4>Cuisine</h4>
<p>${meal.strArea}</p>
</div>
</div>
<div class="container d-flex mt-5 text-start ms-1 px-5">
<div class="row ">
<div class="col">
<h4>Ingredients</h4>
<ul id="ingredientList"> </ul>
</div>
</div>
</div>
<div class="container d-flex text-start mt-5 px-5">
<div class="row">
<div class="col">
<h4>Instruction</h4>
<p>${meal.strInstructions}</p>
</div>
</div>
</div>
</div>
`;
const ingredientList = document.getElementById('ingredientList');
for (let i = 1; i <= 20; i++) {
const ingredient = meal[`strIngredient${i}`];
if (ingredient) {
const measure = meal[`strMeasure${i}`] || ''; // Get the measure or empty string
const listItem = document.createElement('li');
listItem.textContent = `${measure} ${ingredient}`.trim(); // Combine measure and ingredient
ingredientList.appendChild(listItem);
} else {
break; // Stop the loop if ingredient is null
}
}
} else {
mealDiv.innerHTML = '<p>No meal found.</p>';
}
}
// Get the meal_id from the URL and fetch meal details
const mealId = getQueryParameter('meal_id');
if (mealId) {
fetchMealDetails(mealId);
} else {
document.getElementById('mealDetails').innerHTML = '<p>No meal ID provided.</p>';
}
</script>
</div>
</body>
</html>