Skip to content
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

mini-project web fundamentals #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions MiniProject-01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Search for your favorite recipes.

![mini project cover](./assets/recipe-finder.png "recipe-finder")
Binary file added MiniProject-01/assets/favicon.ico
Binary file not shown.
Binary file added MiniProject-01/assets/recipe-finder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions MiniProject-01/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="./assets/favicon.ico" />
<link rel="stylesheet" href="./style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Barriecito&display=swap"
rel="stylesheet"
/>
<title>Mini Project.</title>
</head>
<body id="body">
<div id="blob"></div>
<div id="blur">
<nav class="navbar">
<menu class="menu">
<div id="menuSvgContainer" onclick="">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"
/>
</svg>
</div>
<div id="dropdownMenu">
<div class="sidebarContainer">
<h4>Search History</h4>
<ol id="searchListContainerMenu"></ol>
</div>
</div>
</menu>
</nav>
<section class="layout">
<aside class="sidebar">
<div class="sidebarContainer">
<h4>Search History</h4>
<ol id="searchListContainer"></ol>
</div>
</aside>
<main class="content">
<div class="contentContainer">
<h1 class="contentHeader">Recipe finder</h1>
<form id="contentForm">
<input
id="inputField"
name="input"
type="text"
placeholder="Enter your Prompts here."
required
/>
<button type="submit">Generate</button>
</form>
<div id="cards"></div>
</div>
</main>
</section>
</div>
<script src="./script.js"></script>
</body>
</html>
100 changes: 100 additions & 0 deletions MiniProject-01/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// let loading = document.getElementById("loadingWheel");
const myFormValue = document.getElementById("contentForm");
const searchHistory = [];
const menuSvgContainer = document.getElementById("menuSvgContainer");
const dropdownMenu = document.getElementById("dropdownMenu");

menuSvgContainer.addEventListener("click", function () {
console.log("clicked");
if (dropdownMenu.style.display === "none") {
dropdownMenu.style.display = "block";
} else {
dropdownMenu.style.display = "none";
}
});

myFormValue.addEventListener("submit", (e) => {
e.preventDefault();

const searchValue = document.getElementById("inputField");
if (searchValue.value === "") {
console.log("error");
} else {
callOpenApi(searchValue.value);
searchHistory.push(searchValue.value);
}
});

const callOpenApi = async (searchValue) => {
try {
const response = await fetch(
`https://api.edamam.com/api/recipes/v2?type=public&q=${searchValue}&app_id=c9db7ab6&app_key=159b2efbdd90aec7d4d3852ef7503522`
);
const data = await response.json();
const { hits } = data;
console.log("hits", hits);
if (hits.length > 0) {
const cards = document.getElementById("cards");
cards.innerHTML = "";
hits.forEach((item) => {
const cardDiv = document.createElement("div");
cardDiv.className = "card";

cardDiv.innerHTML = `
<div class="cardContent">
<div class="cardImage">
<Image src="${item.recipe.image}" width="100%" height="220px" alt="${item.recipe.label}"/>
</div>
<div class="cardInfo">
<div class="cardInfoTitle">
<h3>${item.recipe.label}</h3>
<h4>${item.recipe.mealType}</h4>
</div>
</div>
</div>
`;
cards.appendChild(cardDiv);
});
}

if (searchHistory.length > 0) {
const searchListContainer = document.getElementById(
"searchListContainer"
);
const searchListContainerMenu = document.getElementById(
"searchListContainerMenu"
);
searchListContainer.innerHTML = "";
searchListContainerMenu.innerHTML = "";
searchHistory.forEach((item) => {
const list = document.createElement("li");
list.innerHTML = item;
list.id = "searchItem";
searchListContainer.append(list);
});
searchHistory.forEach((item) => {
const list = document.createElement("li");
list.innerHTML = item;
list.id = "searchItem";
searchListContainerMenu.append(list);
});
}
} catch (error) {
alert("error", error);
}
};

/**Animation and Background*/
const blob = document.getElementById("blob");

window.onpointermove = (event) => {
const { clientX, clientY } = event;

blob.animate(
{
left: `${clientX}px`,
top: `${clientY}px`,
},
{ duration: 3000, fill: "forwards" }
);
};
Loading