nagasurendra commited on
Commit
a108d8a
·
verified ·
1 Parent(s): e9e772a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -55
app.py CHANGED
@@ -79,38 +79,6 @@ 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
- /* 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 */
@@ -316,6 +284,23 @@ button {
316
  alert("Your final order has been submitted!");
317
  }
318
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  """
320
  # Authentication and Navigation Logic
321
  def authenticate_user(email, password):
@@ -374,26 +359,7 @@ def app():
374
  menu_output = gr.HTML(value=filter_menu("All"))
375
 
376
  # Button to navigate to Cart Page
377
-
378
- # Floating "View Cart" button (HTML for dynamic positioning)
379
- view_cart_floating_button = gr.HTML(
380
- """
381
- <button id="view-cart-btn" onclick="openCart()">View Cart</button>
382
- <script>
383
- function openCart() {
384
- // Simulate a click event to navigate to the cart
385
- const cartButton = document.querySelector('[data-testid="view-cart-button"]');
386
- if (cartButton) {
387
- cartButton.click();
388
- } else {
389
- alert("Cart navigation button not found!");
390
- }
391
- }
392
- </script>
393
- """
394
- )
395
- # Add the "data-testid" attribute to the Gradio Button for proper referencing
396
- view_cart_navigation_button = gr.Button("View Cart", elem_id="view-cart-button", visible=False)
397
 
398
  # Modal window
399
  modal_window = gr.HTML("""
@@ -475,9 +441,9 @@ def app():
475
  outputs=[login_section, signup_section],
476
  )
477
  # Navigate to Cart Page
478
- view_cart_navigation_button.click(
479
- lambda: (gr.update(visible=False), gr.update(visible=True)),
480
- outputs=[menu_section, cart_section],
481
  )
482
  # Navigate Back to Menu Page
483
  back_to_menu_button.click(
 
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 */
 
284
  alert("Your final order has been submitted!");
285
  }
286
  </script>
287
+ <script>
288
+ // Function to scroll to the top of the page
289
+ function scrollToTop() {
290
+ window.scrollTo({ top: 0, behavior: 'smooth' });
291
+ }
292
+
293
+ // Add a click listener to the "View Cart" button
294
+ document.addEventListener("DOMContentLoaded", function() {
295
+ const viewCartButton = document.querySelector("button:contains('View Cart')");
296
+ if (viewCartButton) {
297
+ viewCartButton.addEventListener("click", function() {
298
+ scrollToTop();
299
+ });
300
+ }
301
+ });
302
+ </script>
303
+
304
  """
305
  # Authentication and Navigation Logic
306
  def authenticate_user(email, password):
 
359
  menu_output = gr.HTML(value=filter_menu("All"))
360
 
361
  # Button to navigate to Cart Page
362
+ view_cart_button = gr.Button("View Cart")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  # Modal window
365
  modal_window = gr.HTML("""
 
441
  outputs=[login_section, signup_section],
442
  )
443
  # Navigate to Cart Page
444
+ view_cart_button.click(
445
+ lambda: (gr.update(visible=False), gr.update(visible=True)),
446
+ outputs=[menu_section, cart_section],
447
  )
448
  # Navigate Back to Menu Page
449
  back_to_menu_button.click(