Update templates/search.html
Browse files- templates/search.html +143 -2
templates/search.html
CHANGED
@@ -66,7 +66,7 @@
|
|
66 |
top: 50%;
|
67 |
transform: translateY(-50%);
|
68 |
display: flex;
|
69 |
-
align-items:
|
70 |
justify-content: center;
|
71 |
}
|
72 |
.avatar-icon {
|
@@ -143,6 +143,10 @@
|
|
143 |
background-color: #fff;
|
144 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
145 |
outline: none;
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
.search-bar-container input::placeholder {
|
148 |
color: #888;
|
@@ -153,6 +157,17 @@
|
|
153 |
font-size: 18px;
|
154 |
color: #888;
|
155 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
.bottom-action-bar {
|
157 |
position: fixed;
|
158 |
bottom: 0;
|
@@ -238,6 +253,10 @@
|
|
238 |
left: 12px;
|
239 |
font-size: 16px;
|
240 |
}
|
|
|
|
|
|
|
|
|
241 |
.avatar-dropdown-container {
|
242 |
right: 10px;
|
243 |
}
|
@@ -296,6 +315,7 @@
|
|
296 |
<div class="search-bar-container">
|
297 |
<input type="text" id="searchBar" class="form-control" placeholder="Search items or sections..." autocomplete="off">
|
298 |
<i class="bi bi-search search-icon"></i>
|
|
|
299 |
</div>
|
300 |
</div>
|
301 |
|
@@ -360,4 +380,125 @@
|
|
360 |
}
|
361 |
|
362 |
function getCartLocalStorage() {
|
363 |
-
return JSON.parse(localStorage.getItem('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
top: 50%;
|
67 |
transform: translateY(-50%);
|
68 |
display: flex;
|
69 |
+
align-items: center;
|
70 |
justify-content: center;
|
71 |
}
|
72 |
.avatar-icon {
|
|
|
143 |
background-color: #fff;
|
144 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
145 |
outline: none;
|
146 |
+
transition: border-bottom 0.3s ease;
|
147 |
+
}
|
148 |
+
.search-bar-container input:focus {
|
149 |
+
border-bottom: 2px solid #FFA07A;
|
150 |
}
|
151 |
.search-bar-container input::placeholder {
|
152 |
color: #888;
|
|
|
157 |
font-size: 18px;
|
158 |
color: #888;
|
159 |
}
|
160 |
+
.mic-icon {
|
161 |
+
position: absolute;
|
162 |
+
right: 15px;
|
163 |
+
font-size: 18px;
|
164 |
+
color: #888;
|
165 |
+
cursor: pointer;
|
166 |
+
transition: color 0.3s ease;
|
167 |
+
}
|
168 |
+
.mic-icon.active {
|
169 |
+
color: #007bff;
|
170 |
+
}
|
171 |
.bottom-action-bar {
|
172 |
position: fixed;
|
173 |
bottom: 0;
|
|
|
253 |
left: 12px;
|
254 |
font-size: 16px;
|
255 |
}
|
256 |
+
.mic-icon {
|
257 |
+
right: 12px;
|
258 |
+
font-size: 16px;
|
259 |
+
}
|
260 |
.avatar-dropdown-container {
|
261 |
right: 10px;
|
262 |
}
|
|
|
315 |
<div class="search-bar-container">
|
316 |
<input type="text" id="searchBar" class="form-control" placeholder="Search items or sections..." autocomplete="off">
|
317 |
<i class="bi bi-search search-icon"></i>
|
318 |
+
<i class="bi bi-mic mic-icon" id="micIcon"></i>
|
319 |
</div>
|
320 |
</div>
|
321 |
|
|
|
380 |
}
|
381 |
|
382 |
function getCartLocalStorage() {
|
383 |
+
return JSON.parse(localStorage.getItem('cart')) || [];
|
384 |
+
}
|
385 |
+
|
386 |
+
function selectItem(itemName) {
|
387 |
+
localStorage.setItem('selectedItem', itemName);
|
388 |
+
window.location.href = '/menu';
|
389 |
+
}
|
390 |
+
|
391 |
+
function filterMenuItems(query) {
|
392 |
+
const menuItemElements = document.querySelectorAll('.menu-item');
|
393 |
+
const noResults = document.getElementById('noResults');
|
394 |
+
let hasResults = false;
|
395 |
+
|
396 |
+
menuItemElements.forEach(item => {
|
397 |
+
const name = item.getAttribute('data-name').toLowerCase();
|
398 |
+
const section = item.getAttribute('data-section').toLowerCase();
|
399 |
+
const matches = name.includes(query.toLowerCase()) || section.includes(query.toLowerCase());
|
400 |
+
item.style.display = matches ? '' : 'none';
|
401 |
+
if (matches) hasResults = true;
|
402 |
+
});
|
403 |
+
|
404 |
+
noResults.style.display = hasResults ? 'none' : 'block';
|
405 |
+
}
|
406 |
+
|
407 |
+
document.addEventListener('DOMContentLoaded', function () {
|
408 |
+
// Avatar Dropdown
|
409 |
+
const avatarContainer = document.querySelector('.avatar-dropdown-container');
|
410 |
+
const dropdownMenu = document.querySelector('.dropdown-menu');
|
411 |
+
avatarContainer.addEventListener('click', function (event) {
|
412 |
+
event.stopPropagation();
|
413 |
+
dropdownMenu.style.display = dropdownMenu.style.display === 'block' ? 'none' : 'block';
|
414 |
+
});
|
415 |
+
document.addEventListener('click', function (event) {
|
416 |
+
if (!avatarContainer.contains(event.target)) {
|
417 |
+
dropdownMenu.style.display = 'none';
|
418 |
+
}
|
419 |
+
});
|
420 |
+
const dropdownItems = document.querySelectorAll('.dropdown-item');
|
421 |
+
dropdownItems.forEach(item => {
|
422 |
+
item.addEventListener('click', function () {
|
423 |
+
dropdownMenu.style.display = 'none';
|
424 |
+
});
|
425 |
+
});
|
426 |
+
|
427 |
+
// Search Bar Functionality
|
428 |
+
const searchBar = document.getElementById('searchBar');
|
429 |
+
const searchQuery = localStorage.getItem('searchQuery');
|
430 |
+
if (searchQuery) {
|
431 |
+
searchBar.value = searchQuery;
|
432 |
+
filterMenuItems(searchQuery);
|
433 |
+
localStorage.removeItem('searchQuery');
|
434 |
+
}
|
435 |
+
searchBar.addEventListener('input', function () {
|
436 |
+
filterMenuItems(this.value);
|
437 |
+
});
|
438 |
+
|
439 |
+
// Voice Recognition
|
440 |
+
const micIcon = document.getElementById('micIcon');
|
441 |
+
if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
|
442 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
443 |
+
const recognition = new SpeechRecognition();
|
444 |
+
recognition.lang = 'en-US';
|
445 |
+
recognition.onstart = () => micIcon.classList.add('active');
|
446 |
+
recognition.onresult = (event) => {
|
447 |
+
const query = event.results[0][0].transcript.trim();
|
448 |
+
searchBar.value = query;
|
449 |
+
filterMenuItems(query);
|
450 |
+
};
|
451 |
+
recognition.onend = () => micIcon.classList.remove('active');
|
452 |
+
recognition.onerror = (event) => {
|
453 |
+
micIcon.classList.remove('active');
|
454 |
+
console.error('Speech error:', event.error);
|
455 |
+
};
|
456 |
+
micIcon.addEventListener('click', () => {
|
457 |
+
recognition.start();
|
458 |
+
});
|
459 |
+
} else {
|
460 |
+
micIcon.style.display = 'none';
|
461 |
+
}
|
462 |
+
|
463 |
+
// Lazy Loading for Cards
|
464 |
+
const menuCards = document.querySelectorAll('.menu-card');
|
465 |
+
const cardObserver = new IntersectionObserver((entries, observer) => {
|
466 |
+
entries.forEach(entry => {
|
467 |
+
if (entry.isIntersecting) {
|
468 |
+
entry.target.classList.add('visible');
|
469 |
+
observer.unobserve(entry.target);
|
470 |
+
}
|
471 |
+
});
|
472 |
+
}, {
|
473 |
+
root: null,
|
474 |
+
rootMargin: '0px',
|
475 |
+
threshold: 0.1
|
476 |
+
});
|
477 |
+
menuCards.forEach(card => cardObserver.observe(card));
|
478 |
+
|
479 |
+
// Fetch Cart
|
480 |
+
fetch('/cart/get')
|
481 |
+
.then(response => {
|
482 |
+
if (!response.ok) {
|
483 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
484 |
+
}
|
485 |
+
return response.json();
|
486 |
+
})
|
487 |
+
.then(data => {
|
488 |
+
if (data.success) {
|
489 |
+
updateCartUI(data.cart);
|
490 |
+
} else {
|
491 |
+
console.error('Failed to fetch cart:', data.error);
|
492 |
+
const cart = getCartLocalStorage();
|
493 |
+
updateCartUI(cart);
|
494 |
+
}
|
495 |
+
})
|
496 |
+
.catch(err => {
|
497 |
+
console.error('Error fetching cart:', err);
|
498 |
+
const cart = getCartLocalStorage();
|
499 |
+
updateCartUI(cart);
|
500 |
+
});
|
501 |
+
});
|
502 |
+
</script>
|
503 |
+
</body>
|
504 |
+
</html>
|