nagasurendra commited on
Commit
81c1404
·
verified ·
1 Parent(s): dc221de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -104
app.py CHANGED
@@ -341,25 +341,10 @@ def app():
341
  # Output area for menu items
342
  menu_output = gr.HTML(value=filter_menu("All"))
343
 
344
- # Floating "View Cart" Button
345
- view_cart_button = gr.HTML('''
346
- <div id="view-cart-button" style="
347
- position: fixed;
348
- bottom: 20px;
349
- right: 20px;
350
- z-index: 1000;
351
- background-color: #007bff;
352
- color: white;
353
- border-radius: 50px;
354
- padding: 10px 20px;
355
- font-size: 16px;
356
- cursor: pointer;
357
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
358
- " onclick="openCartModal()">View Cart</div>
359
- ''')
360
 
361
-
362
- # Modal window for item customization
363
  modal_window = gr.HTML("""
364
  <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
365
  <div style="text-align: right;">
@@ -390,100 +375,31 @@ def app():
390
  <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
391
  </div>
392
  """)
393
-
394
- # Modal for Cart Details
395
- cart_modal = gr.HTML('''
396
- <div id="cart-modal" style="
397
- display: none;
398
- position: fixed;
399
- top: 0;
400
- left: 0;
401
- width: 100%;
402
- height: 100%;
403
- background-color: rgba(0, 0, 0, 0.5);
404
- z-index: 1100;
405
- ">
406
- <div style="
407
- position: absolute;
408
- bottom: 0;
409
- left: 0;
410
- width: 100%;
411
- background: white;
412
- border-radius: 20px 20px 0 0;
413
- padding: 20px;
414
- max-height: 70%;
415
- overflow-y: auto;
416
- box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.2);
417
- ">
418
- <button onclick="closeCartModal()" style="
419
- float: right;
420
- background: none;
421
- border: none;
422
- font-size: 20px;
423
- font-weight: bold;
424
- cursor: pointer;
425
- ">&times;</button>
426
- <h3 style="margin-top: 0;">Your Cart</h3>
427
- <div id="cart-content">
428
- <!-- Cart items will be dynamically updated here -->
429
- </div>
430
- </div>
431
- </div>
432
- ''')
433
-
434
-
435
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
 
 
436
  gr.Row([selected_preference])
437
  gr.Row(menu_output)
438
  gr.Row(modal_window)
439
- gr.Row(view_cart_button)
440
- gr.Row(cart_modal)
441
 
442
- # Add JavaScript for modal behavior
443
- gr.HTML('''
444
- <script>
445
- function openCartModal() {
446
- document.getElementById('cart-modal').style.display = 'block';
447
- }
448
 
449
- function closeCartModal() {
450
- document.getElementById('cart-modal').style.display = 'none';
451
- }
452
 
453
- // Dynamically update the cart content
454
- function updateCartContent(htmlContent) {
455
- document.getElementById('cart-content').innerHTML = htmlContent;
456
- }
457
 
458
- // Ensure existing updateCartDisplay logic works
459
- function updateCartDisplay() {
460
- let totalBill = 0;
461
- let cartHTML = "<div>";
462
- cart.forEach((item, index) => {
463
- totalBill += item.itemTotal;
464
- cartHTML += `<div style="margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; padding: 10px;">
465
- <strong>${item.name}</strong> (x${item.quantity}) - $${item.itemTotal.toFixed(2)}
466
- <br>Extras: ${item.extras.join(", ") || "None"}
467
- <br>Instructions: ${item.instructions || "None"}
468
- </div>`;
469
- });
470
- cartHTML += `</div><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
471
- cartHTML += `<button onclick="submitCart()" style="
472
- background-color: #007bff;
473
- color: white;
474
- padding: 10px 20px;
475
- border: none;
476
- border-radius: 5px;
477
- font-size: 16px;
478
- cursor: pointer;
479
- ">Submit</button>`;
480
- updateCartContent(cartHTML);
481
- }
482
- </script>
483
- ''')
484
 
485
- # Cart & Final Order Page (Not needed as the cart is shown in the modal now)
486
-
487
  # Button Bindings
488
  # Login Button
489
  login_button.click(
@@ -507,9 +423,21 @@ def app():
507
  lambda: (gr.update(visible=True), gr.update(visible=False)),
508
  outputs=[login_section, signup_section],
509
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
510
 
511
  return demo
512
 
513
  if __name__ == "__main__":
514
  app().launch()
515
-
 
341
  # Output area for menu items
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("""
349
  <div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
350
  <div style="text-align: right;">
 
375
  <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
376
  </div>
377
  """)
378
+ # Update menu dynamically based on preference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
380
+
381
+ # Layout
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:
389
+ gr.Markdown("### Cart & Final Order Page")
 
 
 
390
 
391
+ # Floating cart display
392
+ cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
 
393
 
394
+ # Final order display
395
+ final_order_output = gr.HTML(value="", elem_id="final-order")
 
 
396
 
397
+ # Button to navigate back to Menu Page
398
+ back_to_menu_button = gr.Button("Back to Menu")
399
+
400
+ gr.Row(cart_output)
401
+ gr.Row(final_order_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
 
 
 
403
  # Button Bindings
404
  # Login Button
405
  login_button.click(
 
423
  lambda: (gr.update(visible=True), gr.update(visible=False)),
424
  outputs=[login_section, signup_section],
425
  )
426
+ # Navigate to Cart Page
427
+ # Navigate to Cart Page
428
+ view_cart_button.click(
429
+ lambda: (gr.update(visible=False), gr.update(visible=True)),
430
+ outputs=[menu_section, cart_section],
431
+ _js="window.scrollTo({top: 0, behavior: 'smooth'})" # Add this line for scrolling
432
+ )
433
+
434
+ # Navigate Back to Menu Page
435
+ back_to_menu_button.click(
436
+ lambda: (gr.update(visible=True), gr.update(visible=False)),
437
+ outputs=[menu_section, cart_section],
438
+ )
439
 
440
  return demo
441
 
442
  if __name__ == "__main__":
443
  app().launch()