-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed5c630
commit 1954577
Showing
5 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Searching, Debounce, Pagination</title> | ||
<style> | ||
*{ | ||
padding: 0; | ||
margin: 0; | ||
box-sizing: border-box; | ||
} | ||
body{ | ||
padding: 20px; | ||
} | ||
nav{ | ||
margin: 40px; | ||
height: 40px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
nav input{ | ||
padding: 15px; | ||
width: 80%; | ||
} | ||
div{ | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 15px; | ||
text-align: center; | ||
} | ||
.card{ | ||
display: flex; | ||
flex-direction: column; | ||
box-shadow: 0 0 4px rgba(56, 56, 56, 0.55); | ||
border-radius: 10px; | ||
padding: 15px; | ||
} | ||
.card h4{ | ||
margin-top: 10px; | ||
} | ||
.card img{ | ||
border-radius: 10px; | ||
} | ||
.card p{ | ||
margin-bottom: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<nav> | ||
<input type="text" onkeyup="handleSearch(event)" id="search" placeholder="Search"> | ||
</nav> | ||
<div id="cards-container"></div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<link rel="stylesheet" href="locationStyle.css"> | ||
</head> | ||
<body> | ||
<nav class="search-container"> | ||
<input type="text" id="search" onkeyup="handleSearch(event)" placeholder="Search for location"> | ||
<div id="locations"></div> | ||
</nav> | ||
|
||
<script src="location.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const getData = (text) => { | ||
const pr = fetch(`https://google-map-places.p.rapidapi.com/maps/api/place/autocomplete/json?input=${text}&language=en®ion=en`, | ||
{ | ||
method:"GET", | ||
headers: | ||
{ | ||
'x-rapidapi-host': 'google-map-places.p.rapidapi.com', | ||
'x-rapidapi-key': '50724e4e22msh3056f141c1efc51p1ce63ajsn609a39970aa6' | ||
} | ||
} | ||
); | ||
pr.then((res) => { | ||
const pr2 = res.json(); | ||
pr2.then((data) => { | ||
showLocations(data.predictions); | ||
}); | ||
}); | ||
}; | ||
|
||
const root = document.getElementById("locations"); | ||
|
||
const showLocations = (data) => { | ||
root.innerHTML = ""; | ||
data.forEach((elem) => { | ||
const p = document.createElement("p"); | ||
p.innerText = elem.description; | ||
root.appendChild(p); | ||
}); | ||
} | ||
|
||
let timeoutId = null; | ||
const handleSearch = (e) => { | ||
if(timeoutId){ | ||
clearTimeout(timeoutId); | ||
} | ||
timeoutId = setTimeout(() => { | ||
getData(e.target.value); | ||
},200); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.search-container { | ||
position: relative; | ||
width: 100%; | ||
max-width: 400px; | ||
margin: 20px auto; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
#search { | ||
width: 100%; | ||
padding: 10px; | ||
font-size: 16px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
outline: none; | ||
box-sizing: border-box; | ||
} | ||
|
||
#locations { | ||
width: 100%; | ||
background: #fff; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
margin-top: 5px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
max-height: 200px; | ||
overflow-y: auto; | ||
z-index: 1000; | ||
} | ||
|
||
#locations p { | ||
padding: 10px; | ||
margin: 0; | ||
font-size: 14px; | ||
cursor: pointer; | ||
transition: background 0.3s; | ||
} | ||
|
||
#locations p:hover { | ||
background: #f0f0f0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//https://dummyjson.com/recipes/search?q=Margherita | ||
|
||
const getData = (text) => { | ||
const pr = fetch (`https://dummyjson.com/recipes/search?q=${text}`); | ||
pr.then((res) => { | ||
const pr2 = res.json(); | ||
pr2.then((data) => { | ||
showCards(data.recipes); | ||
}); | ||
}); | ||
}; | ||
|
||
const root = document.getElementById("cards-container"); | ||
const showCards = (dataArr) => { | ||
root.innerHTML = ""; | ||
dataArr.forEach((elem) => { | ||
const newDiv = document.createElement("div"); | ||
newDiv.className = "card"; | ||
newDiv.innerHTML = ` | ||
<h4>${elem.name}</h4> | ||
<img src="${elem.image}" height="200px" width="200px"> | ||
<p>${elem.cuisine}</p> | ||
`; | ||
root.appendChild(newDiv); | ||
}); | ||
}; | ||
|
||
let timeoutId = null; | ||
const handleSearch = (e) => { | ||
if(timeoutId){ | ||
clearTimeout(timeoutId); | ||
} | ||
timeoutId = setTimeout(() => { | ||
getData(e.target.value); | ||
},200); | ||
}; |