Skip to content

Commit

Permalink
added show all functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
xyryc committed Oct 13, 2024
1 parent ca1d5bf commit 7c88262
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ <h1 class="text-4xl font-semibold mb-[50px] text-center">
</h1>

<!-- meals cart container -->
<div
id="meals-container"
class="grid grid-cols-1 sm:grid-cols-2 justify-items-center gap-6">
<div
id="meals-container"
class="grid grid-cols-1 sm:grid-cols-2 justify-items-center gap-6"
>
<!-- card -->
<div
class="flex items-center justify-center border rounded-lg hover:bg-gray-100 duration-200 ease-in-out"
Expand Down Expand Up @@ -212,6 +213,7 @@ <h3 class="text-2xl font-bold">Chicken Handi</h3>
<!-- button -->
<div class="text-center mt-[85px]">
<button
onclick="handleShowAll()"
class="text-xl font-bold px-10 py-4 rounded-lg bg-[#FFC107] hover:scale-105 duration-300"
>
Show All
Expand Down Expand Up @@ -287,6 +289,6 @@ <h6 class="mb-4 text-2xl font-bold text-[#403F3F]">Newsletter</h6>
</footer>

<!-- script -->
<script src="./scripts/app.js"></script>
<script src="./scripts/app.js"></script>
</body>
</html>
18 changes: 14 additions & 4 deletions scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const loadAllMeals = async () => {
const loadAllMeals = async (status) => {
const response = await fetch(
"https://www.themealdb.com/api/json/v1/1/filter.php?a=Italian"
);
const data = await response.json();
displayAllMeals(data.meals);

if (status) {
displayAllMeals(data.meals);
} else {
displayAllMeals(data.meals.slice(0, 6));
}
};

const displayAllMeals = (meals) => {
Expand All @@ -28,8 +33,9 @@ const displayAllMeals = (meals) => {
<div class="px-6">
<h3 class="text-2xl font-bold">${meal.strMeal}</h3>
<p class="text-lg leading-[30px] text-[#706F6F] mt-4 mb-6">
There are many variations of passages of available, but the
majority have suffered
This dish features a harmonious blend of flavors, with various interpretations available,
ensuring a delightful culinary experience.
</p>
<button class="text-[#FFC107] font-semibold text-lg underline">
View Details
Expand All @@ -44,4 +50,8 @@ const displayAllMeals = (meals) => {
});
};

const handleShowAll = () => {
loadAllMeals(true);
};

loadAllMeals();

0 comments on commit 7c88262

Please sign in to comment.