nagasurendra commited on
Commit
a25cb6d
·
verified ·
1 Parent(s): 8b00247

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -285,6 +285,16 @@ button {
285
  }
286
  </script>
287
  """
 
 
 
 
 
 
 
 
 
 
288
  # Authentication and Navigation Logic
289
  def authenticate_user(email, password):
290
  if check_credentials(email, password):
@@ -342,7 +352,7 @@ def app():
342
  menu_output = gr.HTML(value=filter_menu("All"))
343
 
344
  # Button to navigate to Cart Page
345
- view_cart_button = gr.Button("View Cart")
346
 
347
  # Modal window
348
  modal_window = gr.HTML("""
@@ -382,7 +392,7 @@ def app():
382
  gr.Row([selected_preference])
383
  gr.Row(menu_output)
384
  gr.Row(modal_window)
385
- gr.HTML(modal_and_cart_js)
386
 
387
  # Cart & Final Order Page
388
  with gr.Column(visible=False) as cart_section:
@@ -424,28 +434,10 @@ def app():
424
  outputs=[login_section, signup_section],
425
  )
426
  # Navigate to Cart Page
427
- # Navigate to Cart Page
428
- # HTML component to execute JavaScript
429
- scroll_to_top_js = gr.HTML(
430
- """
431
- <script>
432
- function scrollToTop() {
433
- window.scrollTo({top: 0, behavior: 'smooth'});
434
- }
435
- </script>
436
- """
437
- )
438
-
439
- # Navigate to Cart Page with Scroll-to-Top Behavior
440
  view_cart_button.click(
441
  lambda: (gr.update(visible=False), gr.update(visible=True)),
442
- outputs=[menu_section, cart_section]
443
  )
444
-
445
- # Ensure JavaScript runs when switching to the cart page
446
- view_cart_button.click(None, None, _js="scrollToTop()")
447
-
448
-
449
  # Navigate Back to Menu Page
450
  back_to_menu_button.click(
451
  lambda: (gr.update(visible=True), gr.update(visible=False)),
 
285
  }
286
  </script>
287
  """
288
+ scroll_to_top_js = """
289
+ <script>
290
+ document.addEventListener('DOMContentLoaded', function () {
291
+ const cartButton = document.querySelector('button[gr-id="view_cart_button"]');
292
+ cartButton.addEventListener('click', () => {
293
+ window.scrollTo({ top: 0, behavior: "smooth" });
294
+ });
295
+ });
296
+ </script>
297
+ """
298
  # Authentication and Navigation Logic
299
  def authenticate_user(email, password):
300
  if check_credentials(email, password):
 
352
  menu_output = gr.HTML(value=filter_menu("All"))
353
 
354
  # Button to navigate to Cart Page
355
+ view_cart_button = gr.Button("View Cart", elem_id="view_cart_button")
356
 
357
  # Modal window
358
  modal_window = gr.HTML("""
 
392
  gr.Row([selected_preference])
393
  gr.Row(menu_output)
394
  gr.Row(modal_window)
395
+ gr.HTML(modal_and_cart_js + scroll_to_top_js)
396
 
397
  # Cart & Final Order Page
398
  with gr.Column(visible=False) as cart_section:
 
434
  outputs=[login_section, signup_section],
435
  )
436
  # Navigate to Cart Page
 
 
 
 
 
 
 
 
 
 
 
 
 
437
  view_cart_button.click(
438
  lambda: (gr.update(visible=False), gr.update(visible=True)),
439
+ outputs=[menu_section, cart_section],
440
  )
 
 
 
 
 
441
  # Navigate Back to Menu Page
442
  back_to_menu_button.click(
443
  lambda: (gr.update(visible=True), gr.update(visible=False)),