Oops... 😣 No recipes found
+diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..9ef2be26a Binary files /dev/null and b/.DS_Store differ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/README.md b/README.md index 58f1a8a66..9494db63e 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ # js-project-recipe-library + +Link to letlify: +https://js-project-recipe-library-site.netlify.app/ \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 000000000..eeade79fe --- /dev/null +++ b/index.html @@ -0,0 +1,83 @@ + + +
+ + + +Oops... 😣 No recipes found
+No favorite recipes yet ❤️
`; + } +}); + + + +//=============================== +// display recipes +//=============================== + +const displayRecipes = (recipeArray) => { + container.innerHTML = "" //reset the container + + recipeArray.forEach(recipe => { + // ingredients + let ingredients = []; + if (recipe.extendedIngredients && Array.isArray(recipe.extendedIngredients)) { + ingredients = recipe.extendedIngredients.map(ing => ing.original); + } + + container.innerHTML += ` +No recipes found 🥲 Check your API key or quota.
`; + } + + } catch (error) { + console.error("Error fetching data:", error); + showErrorMessage(); + } +}; + +// API error message +const showApiLimitMessage = () => { + container.innerHTML = ` +
+ ⚠️ API limit reached for today ⚠️
+ Please try again tomorrow.
+
+ Something went wrong while fetching recipes 🥲
+ Please try again later.
+
No recipes found
`; + } +}; + +//=============================== +// pick a random recipe +//=============================== + +// change the color of the button when clicked +randomBtn.addEventListener("click", () => { + randomBtn.classList.toggle("active"); +}) + +randomBtn.addEventListener("click", () => { + const randomIndex = Math.floor(Math.random() * results.length); + const randomRecipe = results[randomIndex]; + displayRecipes([randomRecipe]) +}) + + +//=============================== +// search recipes +//=============================== + +const searchInput = document.getElementById("text-input"); +const noResultsMessage = document.getElementById("no-results"); + +// show and hide search results +const showSearchResult = (target) => target.style.display = ""; +const hideSearchResult = (target) => target.style.display = "none"; + +// search recipes by keyword +const filterSearchResults = () => { + const keyword = searchInput.value.trim().toLowerCase(); + const searchTargets = document.querySelectorAll('.recipe-card'); + let matchFound = false; + + searchTargets.forEach((target) => { + const text = target.textContent.toLowerCase(); + // check if the keyword is in the text content and show/hide the recipe card + if (text.includes(keyword)) { + showSearchResult(target); + matchFound = true; + } else { + hideSearchResult(target); + } + }); + + // show no results message if no hits + if (!matchFound && keyword.length > 0) { + noResultsMessage.style.display = "block"; + } else { + noResultsMessage.style.display = "none"; + } +}; + +// add event listener to the search input +searchInput.addEventListener("input", filterSearchResults); + diff --git a/style.css b/style.css new file mode 100644 index 000000000..f6ae248e5 --- /dev/null +++ b/style.css @@ -0,0 +1,325 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: "Futura", sans-serif; + background-color: #fafbff; +} + +h1 { + color: #0018a4; + height: 85px; + top: 64px; + left: 64px; + font-size: 3rem; + margin: 50px 10px; +} + +h3 { + color: #000000; + font-size: 22px; + margin: 10px 0 10px 16px; +} + +h4 { + color: #000000; +} + +p { + color: #000000; +} + +img { + width: 100%; + height: 200px; + border-radius: 12px; + object-fit: cover; +} + +ul { + padding: 0; +} + +li { + list-style: none; +} + +a { + text-decoration: none; + color: initial; +} + +/* ====================================== +favorite recipes button +======================================= */ + +.favorites { + color: #555; + text-align: center; + margin-left: 10px; + margin-bottom: 50px; + background-color: lightpink; + width: 150px; + padding: 10px; + border-radius: 10px; + cursor: pointer; +} + +.favorites:hover { + border: 2px solid #0018a4; + box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1); +} + +/* ====================================== +search form +======================================= */ + +.search-form { + display: flex; + justify-content: space-between; + align-items: center; + width: 50%; + margin-left: 10px; + margin-bottom: 20px; + overflow: hidden; + border: 1px solid #777777; + border-radius: 50px; +} + +.search-form:hover { + border: 2px solid #777777; +} + +#text-input { + width: 100%; + height: 45px; + padding: 5px 15px; + border: none; + box-sizing: border-box; + font-size: 1em; + outline: none; +} + +#text-input::placeholder{ + font-size: 1em; + color: #777777; +} + +.search-button { + background-color: skyblue; + display: flex; + justify-content: center; + align-items: center; + width: 50px; + height: 45px; + border: none; + cursor: pointer; +} + +.search-emoji { + font-size: 1.5rem; +} + +/* ====================================== +style for the buttons +======================================= */ + +.button-container { + display: flex; + flex-direction: row; + margin-bottom: 20px; + gap: 30px; +} + +.filter-container, +.sort-container { + display: flex; + flex-direction: column; +} + +.filter, +.sort, +.random { + display: flex; + flex-wrap: wrap; + flex-direction: row; +} + +.filter-btn { + text-align: center; + background-color: #ccffe2; + color: #0018a4; + font-size: 18px; + border: none; + width: auto; + height: 40px; + border-radius: 50px; + padding: 8px 16px; + margin: 5px; + cursor: pointer; +} + +.sort-btn { + text-align: center; + background-color: #ffecea; + color: #0018a4; + font-size: 18px; + border: none; + width: auto; + height: 40px; + border-radius: 50px; + padding: 8px 16px; + margin: 5px; + cursor: pointer; +} + +.random-btn { + text-align: center; + background-color: beige; + color: #0018a4; + font-size: 18px; + border: none; + width: auto; + height: 40px; + border-radius: 50px; + padding: 8px 16px; + margin: 5px; + cursor: pointer; +} + +.filter-btn:hover, +.sort-btn:hover, +.random-btn:hover { + border: 2px solid #0018a4; + box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1); +} + +.filter-btn.active { + background-color: #0018a4; + color: #fff; +} + +.sort-btn.active { + background-color: #ff6589; + color: #fff; +} + +.random-btn.active { + background-color: orange; + color: #fff; +} + +/* ====================================== +style for recipe cards +======================================= */ + +#recipe-container { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); + gap: 10px; + margin-bottom: 50px; +} + +.placeholder p { + opacity: 1; + margin: 8px 0; +} + +.recipe-image { + position: relative; +} + +.like-button { + position: absolute; + top: 10px; + right: 10px; + width: 40px; + height: 40px; + font-size: 24px; + background-color: white; + border-radius: 50%; + border: none; + margin: 0 0 0 auto;cursor: pointer; +} + +.like-button.liked { + color: red; +} + +.line { + width: auto; + height: 1px; + margin: 20px 0; +} + +.view-recipe-button { + background-color: #ff6589; + font-size: large; + border: none; + border-radius: 10px; + width: 100%; + padding: 10px; + cursor: pointer; + text-decoration: none; + margin-top: auto; + text-align: center; + align-items: flex-end; +} + +.view-recipe-button a { + color: white; +} + +.recipe-card { + display: flex; + flex-direction: column; + max-width: 300px; + height: 100%; + border: 1px solid #e9e9e9; + border-radius: 16px; + margin: 10px; + padding: 16px 16px 24px 16px; + background-color: #fff; +} + +/* to place view recipe button in the bottom of the card */ +.recipe-card > *:not(.recipe-image):not(.view-recipe-button) { + margin-top: 12px; +} + +.recipe-card:hover { + box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.1); +} + +.no-results { + text-align: center; + margin-top: 100px; + font-size: 2rem; + color: #555; +} + +#no-results { + text-align: center; + margin-top: 100px; + font-size: 2rem; + color: #555; + display: none; +} + +/* ====================================== +responsive design +======================================= */ + +@media (max-width: 1023px) { + .button-container { + display: flex; + flex-direction: column ; + } + + .search-form { + width: 90%; + } +}