-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
121 lines (113 loc) · 3.63 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="./CSS/Navbar.css">
<link rel="stylesheet" href="./CSS/getreceipe.css">
</head>
<style>
#search {
/* background-color: aqua; */
text-align: center;
margin-bottom: 10px;
display: flex;
justify-content: center;
}
#query {
padding: 10px 20px;
font-size: 20px;
width: 400px;
border-top-left-radius: 18px;
border-bottom-left-radius: 18px;
}
#query+button {
padding: 6px 20px;
font-size: 20px;
margin-left: -4px;
border-top-right-radius: 18px;
border-bottom-right-radius: 18px;
background-color: brown;
font-size: 25px;
font-weight: bold;
}
</style>
<body>
<body>
<div id="NavBar"></div>
<h1>Search Receipe by Name</h1>
<div id="search">
<input type="text" oninput="debounce(main,1000)" id="query" placeholder="Search for a Meals...">
<button onclick="getData()">Search</button>
</div>
<div id="displayRecipes"></div>
</body>
</html>
<script type="module">
// Navbar
let NavBar = document.getElementById("NavBar");
import navbarMeals from './Components/Navbar.js'
// console.log('navbarMeals:', navbarMeals())
NavBar.innerHTML = navbarMeals();
</script>
<script>
//search Meals over here
// import { append } from "./scripts/appendData.js";
var data;
var id;
let displayRecipes = document.getElementById("displayRecipes");
async function main() {
try {
let query = document.getElementById("query").value;
console.log('query:', query);
let res = await fetch(`https://www.themealdb.com/api/json/v1/1/search.php?s=${query}`)
// console.log('res:', res);
let data = await res.json();
console.log('data:', data);
// append(data.meals, displayRecipes);
append(data);
}
catch {
console.log(err)
}
}
function append(data) {
displayRecipes.innerHTML = null;
data.meals.forEach(({ strMeal, strMealThumb }) => {
console.log('strMeal,strMealThumb:', strMeal, strMealThumb)
let div = document.createElement('div');
let p = document.createElement('p');
let img = document.createElement('img');
p.innerText = strMeal;
img.src = strMealThumb;
div.append(img, p);
displayRecipes.append(div);
})
}
function debounce(func, delay) {
if (id) {
clearInterval(id);
}
id = setTimeout(() => {
func();
}, delay);
}
let usernameDisplay = JSON.parse(localStorage.getItem("username"));
let userDisplay = document.getElementById("userDisplay");
console.log('userDisplay:', userDisplay.innerHTML)
console.log('usernameDisplay:', usernameDisplay)
userDisplay.innerHTML = "ASHISH"
</script>
<script type="module">
//get Random Meals
import { getData, append } from "./scripts/fetchAppend.js";
let str = ["a", "d", "e", "j", "n", "o", "h", "v", "a"]
var num = Math.ceil(Math.random() * (str.length - 1))
console.log('num:', num)
var random = str[num]
let res = await getData(`https://www.themealdb.com/api/json/v1/1/search.php?f=${random}`);
console.log('res:', res);
append(res.meals, displayRecipes)
</script>