File size: 1,987 Bytes
b3d4ab4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# modules/ui/router.py
import gradio as gr
from .views.landing import create_landing_view
from .views.login import create_login_view
from .views.user_dashboard import create_dashboard_view
from ..auth.session import SessionManager
class Router:
def __init__(self):
self.session = SessionManager()
self.current_view = "landing"
def switch_view(self, to_view, **kwargs):
"""Cambia entre vistas y actualiza el estado de la sesi贸n"""
self.current_view = to_view
views = {
"landing": [True, False, False],
"login": [False, True, False],
"dashboard": [False, False, True]
}
if kwargs:
self.session.update(**kwargs)
return [gr.update(visible=v) for v in views[to_view]]
def create_router():
"""Crea y configura el router principal de la aplicaci贸n"""
router = Router()
with gr.Blocks(css="footer {display: none}") as app:
# Contenedores para cada vista
with gr.Group(visible=True) as landing_container:
landing_view = create_landing_view()
with gr.Group(visible=False) as login_container:
login_view = create_login_view()
with gr.Group(visible=False) as dashboard_container:
dashboard_view = create_dashboard_view()
# Configurar navegaci贸n
def handle_navigation(view_name, **kwargs):
return router.switch_view(view_name, **kwargs)
# Conectar eventos de navegaci贸n
landing_view.submit(
fn=lambda: handle_navigation("login"),
outputs=[landing_container, login_container, dashboard_container]
)
login_view.submit(
fn=lambda username, role: handle_navigation("dashboard", username=username, role=role),
inputs=[login_view.username, login_view.role],
outputs=[landing_container, login_container, dashboard_container]
)
return app |