Update templates/search.html
Browse files- templates/search.html +117 -2
templates/search.html
CHANGED
|
@@ -455,6 +455,12 @@
|
|
| 455 |
</div>
|
| 456 |
</div>
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
<div class="container mt-4">
|
| 459 |
<h1 class="menu-heading">Search Menu Items</h1>
|
| 460 |
<div class="row" id="menuItems">
|
|
@@ -552,8 +558,8 @@
|
|
| 552 |
return;
|
| 553 |
}
|
| 554 |
|
| 555 |
-
const filteredItems = menuItems.filter(item =>
|
| 556 |
-
item.name.toLowerCase().includes(query.toLowerCase()) ||
|
| 557 |
item.section.toLowerCase().includes(query.toLowerCase())
|
| 558 |
);
|
| 559 |
|
|
@@ -578,6 +584,63 @@
|
|
| 578 |
searchPopup.style.display = 'block';
|
| 579 |
}
|
| 580 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
document.addEventListener('DOMContentLoaded', function () {
|
| 582 |
// Avatar Dropdown
|
| 583 |
const avatarContainer = document.querySelector('.avatar-dropdown-container');
|
|
@@ -665,7 +728,59 @@
|
|
| 665 |
const cart = getCartLocalStorage();
|
| 666 |
updateCartUI(cart);
|
| 667 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
</script>
|
| 670 |
</body>
|
| 671 |
</html>
|
|
|
|
| 455 |
</div>
|
| 456 |
</div>
|
| 457 |
|
| 458 |
+
<!-- Timer and Success Message Container -->
|
| 459 |
+
<div id="orderTimerContainer" style="display: none; text-align: center; margin-top: 20px;">
|
| 460 |
+
<div id="orderTimer" style="font-size: 1.5rem; font-weight: bold; color: #FFA07A;"></div>
|
| 461 |
+
<div id="orderSuccessMessage" style="font-size: 1.5rem; font-weight: bold; color: #0FAA39; display: none;">Order Successfully Placed!</div>
|
| 462 |
+
</div>
|
| 463 |
+
|
| 464 |
<div class="container mt-4">
|
| 465 |
<h1 class="menu-heading">Search Menu Items</h1>
|
| 466 |
<div class="row" id="menuItems">
|
|
|
|
| 558 |
return;
|
| 559 |
}
|
| 560 |
|
| 561 |
+
const filteredItems = menuItems.filter(item =>
|
| 562 |
+
item.name.toLowerCase().includes(query.toLowerCase()) ||
|
| 563 |
item.section.toLowerCase().includes(query.toLowerCase())
|
| 564 |
);
|
| 565 |
|
|
|
|
| 584 |
searchPopup.style.display = 'block';
|
| 585 |
}
|
| 586 |
|
| 587 |
+
// Timer and Success Message Functions
|
| 588 |
+
let orderTimerInterval;
|
| 589 |
+
let orderDurationInSeconds = 0; // Set your desired order completion time in seconds
|
| 590 |
+
|
| 591 |
+
function startOrderTimer(durationInSeconds) {
|
| 592 |
+
orderDurationInSeconds = durationInSeconds;
|
| 593 |
+
const timerElement = document.getElementById('orderTimer');
|
| 594 |
+
const successMessageElement = document.getElementById('orderSuccessMessage');
|
| 595 |
+
const timerContainer = document.getElementById('orderTimerContainer');
|
| 596 |
+
|
| 597 |
+
if (!timerElement || !successMessageElement || !timerContainer) {
|
| 598 |
+
console.error("Timer elements not found.");
|
| 599 |
+
return;
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
timerContainer.style.display = 'block';
|
| 603 |
+
successMessageElement.style.display = 'none';
|
| 604 |
+
|
| 605 |
+
let secondsRemaining = orderDurationInSeconds;
|
| 606 |
+
|
| 607 |
+
timerElement.innerText = formatTime(secondsRemaining);
|
| 608 |
+
timerElement.style.display = 'block'; // Ensure timer is visible when starting
|
| 609 |
+
|
| 610 |
+
orderTimerInterval = setInterval(() => {
|
| 611 |
+
secondsRemaining--;
|
| 612 |
+
|
| 613 |
+
if (secondsRemaining <= 0) {
|
| 614 |
+
clearInterval(orderTimerInterval);
|
| 615 |
+
timerElement.style.display = 'none';
|
| 616 |
+
successMessageElement.style.display = 'block';
|
| 617 |
+
// Optionally hide the container after a few seconds
|
| 618 |
+
setTimeout(() => {
|
| 619 |
+
timerContainer.style.display = 'none';
|
| 620 |
+
successMessageElement.style.display = 'none';
|
| 621 |
+
timerElement.style.display = 'block'; // Reset for next order
|
| 622 |
+
}, 5000); // Hide after 5 seconds
|
| 623 |
+
} else {
|
| 624 |
+
timerElement.innerText = formatTime(secondsRemaining);
|
| 625 |
+
}
|
| 626 |
+
}, 1000);
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
function formatTime(seconds) {
|
| 630 |
+
const minutes = Math.floor(seconds / 60);
|
| 631 |
+
const remainingSeconds = seconds % 60;
|
| 632 |
+
const formattedMinutes = String(minutes).padStart(2, '0');
|
| 633 |
+
const formattedSeconds = String(remainingSeconds).padStart(2, '0');
|
| 634 |
+
return `${formattedMinutes}:${formattedSeconds}`;
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
// Function to simulate placing a new order (replace with your actual order logic)
|
| 638 |
+
// This function should be called when a new order is successfully processed.
|
| 639 |
+
function handleNewOrderSuccess(estimatedCompletionTimeInSeconds) {
|
| 640 |
+
console.log("New order successful, starting timer...");
|
| 641 |
+
startOrderTimer(estimatedCompletionTimeInSeconds);
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
document.addEventListener('DOMContentLoaded', function () {
|
| 645 |
// Avatar Dropdown
|
| 646 |
const avatarContainer = document.querySelector('.avatar-dropdown-container');
|
|
|
|
| 728 |
const cart = getCartLocalStorage();
|
| 729 |
updateCartUI(cart);
|
| 730 |
});
|
| 731 |
+
|
| 732 |
+
// --- Timer Logic Integration ---
|
| 733 |
+
// You need to call handleNewOrderSuccess() when a new order is successfully placed.
|
| 734 |
+
// This is where you'll connect this frontend timer to your backend order process.
|
| 735 |
+
// For demonstration purposes, let's simulate a new order after the page loads
|
| 736 |
+
// with a fixed duration (e.g., 30 seconds).
|
| 737 |
+
// In a real application, this call would happen after the user confirms an order
|
| 738 |
+
// on a different page (like a checkout or confirmation page).
|
| 739 |
+
// Example:
|
| 740 |
+
// handleNewOrderSuccess(30); // Simulate a new order with a 30-second timer
|
| 741 |
+
// You would likely pass the estimated time from your backend here.
|
| 742 |
+
|
| 743 |
+
// --- Persistence (Optional but Recommended) ---
|
| 744 |
+
// To make the timer persist across page loads, you can store the order's
|
| 745 |
+
// start time and estimated duration in local storage.
|
| 746 |
+
// When the page loads, check local storage for timer data and resume the timer
|
| 747 |
+
// if an active order exists.
|
| 748 |
+
|
| 749 |
+
const savedOrderTimer = localStorage.getItem('orderTimer');
|
| 750 |
+
if (savedOrderTimer) {
|
| 751 |
+
const timerData = JSON.parse(savedOrderTimer);
|
| 752 |
+
const now = Date.now();
|
| 753 |
+
const elapsed = Math.floor((now - timerData.startTime) / 1000);
|
| 754 |
+
const remaining = timerData.duration - elapsed;
|
| 755 |
+
|
| 756 |
+
if (remaining > 0) {
|
| 757 |
+
startOrderTimer(remaining);
|
| 758 |
+
} else {
|
| 759 |
+
// Timer has already finished, show success message briefly
|
| 760 |
+
const successMessageElement = document.getElementById('orderSuccessMessage');
|
| 761 |
+
const timerContainer = document.getElementById('orderTimerContainer');
|
| 762 |
+
timerContainer.style.display = 'block';
|
| 763 |
+
successMessageElement.style.display = 'block';
|
| 764 |
+
setTimeout(() => {
|
| 765 |
+
timerContainer.style.display = 'none';
|
| 766 |
+
successMessageElement.style.display = 'none';
|
| 767 |
+
}, 3000); // Show success for 3 seconds
|
| 768 |
+
localStorage.removeItem('orderTimer'); // Clear finished timer data
|
| 769 |
+
}
|
| 770 |
+
}
|
| 771 |
});
|
| 772 |
+
|
| 773 |
+
// --- Add this to your order placement success logic ---
|
| 774 |
+
// When you successfully place a new order (e.g., after a fetch/API call),
|
| 775 |
+
// call this function to start the timer and save its state.
|
| 776 |
+
function handleOrderPlacedAndStartTimer(estimatedCompletionTimeInSeconds) {
|
| 777 |
+
const startTime = Date.now();
|
| 778 |
+
localStorage.setItem('orderTimer', JSON.stringify({
|
| 779 |
+
startTime: startTime,
|
| 780 |
+
duration: estimatedCompletionTimeInSeconds
|
| 781 |
+
}));
|
| 782 |
+
startOrderTimer(estimatedCompletionTimeInSeconds);
|
| 783 |
+
}
|
| 784 |
</script>
|
| 785 |
</body>
|
| 786 |
</html>
|