Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,6 +79,38 @@ def filter_menu(preference):
|
|
| 79 |
return html_content
|
| 80 |
# Preserving your JavaScript for modal and cart functionality (Your original JavaScript logic)
|
| 81 |
modal_and_cart_js = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
<style>
|
| 83 |
.cart-container {
|
| 84 |
width: 90%; /* Ensure it fits the screen */
|
|
@@ -285,22 +317,6 @@ button {
|
|
| 285 |
}
|
| 286 |
</script>
|
| 287 |
"""
|
| 288 |
-
scroll_to_top_js = """
|
| 289 |
-
<script>
|
| 290 |
-
// Function to scroll to the top of the page when navigating
|
| 291 |
-
function scrollToTop() {
|
| 292 |
-
window.scrollTo({ top: 0, behavior: "smooth" });
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
// Attach scroll-to-top functionality to buttons dynamically
|
| 296 |
-
document.addEventListener('DOMContentLoaded', function () {
|
| 297 |
-
const viewCartButton = document.querySelector('button[gr-id="view_cart_button"]');
|
| 298 |
-
if (viewCartButton) {
|
| 299 |
-
viewCartButton.addEventListener('click', scrollToTop);
|
| 300 |
-
}
|
| 301 |
-
});
|
| 302 |
-
</script>
|
| 303 |
-
"""
|
| 304 |
# Authentication and Navigation Logic
|
| 305 |
def authenticate_user(email, password):
|
| 306 |
if check_credentials(email, password):
|
|
@@ -358,7 +374,12 @@ def app():
|
|
| 358 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 359 |
|
| 360 |
# Button to navigate to Cart Page
|
| 361 |
-
view_cart_button = gr.Button("View Cart"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
# Modal window
|
| 364 |
modal_window = gr.HTML("""
|
|
@@ -398,7 +419,7 @@ def app():
|
|
| 398 |
gr.Row([selected_preference])
|
| 399 |
gr.Row(menu_output)
|
| 400 |
gr.Row(modal_window)
|
| 401 |
-
gr.HTML(modal_and_cart_js
|
| 402 |
|
| 403 |
# Cart & Final Order Page
|
| 404 |
with gr.Column(visible=False) as cart_section:
|
|
@@ -439,20 +460,9 @@ def app():
|
|
| 439 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 440 |
outputs=[login_section, signup_section],
|
| 441 |
)
|
|
|
|
| 442 |
view_cart_button.click(
|
| 443 |
-
fn=None, # No Python function needed
|
| 444 |
-
inputs=None,
|
| 445 |
-
outputs=None,
|
| 446 |
-
_js=scroll_to_top_js, # JavaScript for scrolling to the top
|
| 447 |
-
).then(
|
| 448 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 449 |
-
inputs=None,
|
| 450 |
-
outputs=[menu_section, cart_section],
|
| 451 |
-
)
|
| 452 |
-
|
| 453 |
-
back_to_menu_button.click(
|
| 454 |
-
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 455 |
-
inputs=None,
|
| 456 |
outputs=[menu_section, cart_section],
|
| 457 |
)
|
| 458 |
# Navigate Back to Menu Page
|
|
@@ -464,4 +474,4 @@ def app():
|
|
| 464 |
return demo
|
| 465 |
|
| 466 |
if __name__ == "__main__":
|
| 467 |
-
app().launch()
|
|
|
|
| 79 |
return html_content
|
| 80 |
# Preserving your JavaScript for modal and cart functionality (Your original JavaScript logic)
|
| 81 |
modal_and_cart_js = """
|
| 82 |
+
<style>
|
| 83 |
+
/* Floating Cart Button */
|
| 84 |
+
#view-cart-btn {
|
| 85 |
+
position: fixed;
|
| 86 |
+
bottom: 20px; /* Default to bottom for mobile */
|
| 87 |
+
right: 20px;
|
| 88 |
+
background-color: #007bff;
|
| 89 |
+
color: white;
|
| 90 |
+
border: none;
|
| 91 |
+
padding: 15px 20px;
|
| 92 |
+
border-radius: 50px;
|
| 93 |
+
font-size: 16px;
|
| 94 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
| 95 |
+
cursor: pointer;
|
| 96 |
+
z-index: 1000;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
@media (min-width: 768px) {
|
| 100 |
+
#view-cart-btn {
|
| 101 |
+
top: 20px; /* Move to top for larger screens (laptop/desktop) */
|
| 102 |
+
bottom: unset; /* Remove bottom positioning */
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
</style>
|
| 106 |
+
|
| 107 |
+
<script>
|
| 108 |
+
function openCart() {
|
| 109 |
+
// Trigger the click event to show the cart
|
| 110 |
+
document.querySelector('[data-testid="view-cart"]').click();
|
| 111 |
+
}
|
| 112 |
+
</script>
|
| 113 |
+
|
| 114 |
<style>
|
| 115 |
.cart-container {
|
| 116 |
width: 90%; /* Ensure it fits the screen */
|
|
|
|
| 317 |
}
|
| 318 |
</script>
|
| 319 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
# Authentication and Navigation Logic
|
| 321 |
def authenticate_user(email, password):
|
| 322 |
if check_credentials(email, password):
|
|
|
|
| 374 |
menu_output = gr.HTML(value=filter_menu("All"))
|
| 375 |
|
| 376 |
# Button to navigate to Cart Page
|
| 377 |
+
view_cart_button = gr.Button("View Cart")
|
| 378 |
+
view_cart_floating_button = gr.HTML(
|
| 379 |
+
"""
|
| 380 |
+
<button id="view-cart-btn" onclick="openCart()">View Cart</button>
|
| 381 |
+
"""
|
| 382 |
+
)
|
| 383 |
|
| 384 |
# Modal window
|
| 385 |
modal_window = gr.HTML("""
|
|
|
|
| 419 |
gr.Row([selected_preference])
|
| 420 |
gr.Row(menu_output)
|
| 421 |
gr.Row(modal_window)
|
| 422 |
+
gr.HTML(modal_and_cart_js)
|
| 423 |
|
| 424 |
# Cart & Final Order Page
|
| 425 |
with gr.Column(visible=False) as cart_section:
|
|
|
|
| 460 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 461 |
outputs=[login_section, signup_section],
|
| 462 |
)
|
| 463 |
+
# Navigate to Cart Page
|
| 464 |
view_cart_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
outputs=[menu_section, cart_section],
|
| 467 |
)
|
| 468 |
# Navigate Back to Menu Page
|
|
|
|
| 474 |
return demo
|
| 475 |
|
| 476 |
if __name__ == "__main__":
|
| 477 |
+
app().launch()
|