Skip to content

50Projects-HTML-CSS-JavaScript : Recipe app #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ In order to run this project you need:
</details>
</li>

<li>
<details>
<summary>Recipe App</summary>
<p>The Recipe App is designed to make cooking enjoyable and easy for everyone, from beginners to seasoned chefs. Discover a wide range of recipes, create your own, and share them with the community. With an intuitive interface and smart features, it helps you explore new dishes, organize your favorite recipes, and plan meals for any occasion.</p>
<ul>
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/RecipeApp/">Live Demo</a></li>
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/RecipeApp">Source</a></li>
</ul>
</details>
</li>

</ol>

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
19 changes: 19 additions & 0 deletions Source-Code/RecipeApp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recipe App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Recipe App</h1>
<div class="search-box">
<input type="text" id="search-input" placeholder="Search for recipes...">
<button id="search">Search</button>
</div>
<div class="recipes" id="recipes"></div>
</div>
<script src="script.js"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions Source-Code/RecipeApp/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable no-use-before-define */

const searchRecipes = async () => {
const query = document.getElementById('search-input').value;
if (!query) return;

try {
const response = await fetch(
`https://www.themealdb.com/api/json/v1/1/search.php?s=${query}`,
);
const data = await response.json();
displayRecipes(data.meals);
} catch (error) {
console.error('Error fetching recipes:', error);
}
};

const displayRecipes = (meals) => {
const recipesContainer = document.getElementById('recipes');
recipesContainer.innerHTML = '';

if (!meals) {
recipesContainer.innerHTML = '<p>No recipes found!</p>';
return;
}

meals.forEach((meal) => {
const recipe = document.createElement('div');
recipe.className = 'recipe';
recipe.innerHTML = `
<img src="${meal.strMealThumb}" alt="${meal.strMeal}">
<h3>${meal.strMeal}</h3>
<a href="${meal.strSource}" target="_blank">View Recipe</a>
`;
recipesContainer.appendChild(recipe);
});
};
document.getElementById('search').addEventListener('click', searchRecipes);
61 changes: 61 additions & 0 deletions Source-Code/RecipeApp/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
body {
font-family: Arial, sans-serif;
background-color: #f8f8f8;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

h1 {
text-align: center;
color: #333;
}

.search-box {
display: flex;
gap: 20px;
}

input[type="text"] {
min-width: 300px;
max-width: 400px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}

button {
padding: 10px 20px;
font-size: 16px;
background: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background: #218838;
}

.recipes {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
}

.recipe {
background: #f4f4f4;
padding: 15px;
border-radius: 8px;
text-align: center;
}

.recipe img {
width: 100%;
border-radius: 8px;
}