|
|
|
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: |
|
|
|
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() |
|
|
|
|
|
def handle_navigation(view_name, **kwargs): |
|
return router.switch_view(view_name, **kwargs) |
|
|
|
|
|
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 |