AIdeaText commited on
Commit
b3d4ab4
verified
1 Parent(s): 442dde9

Update modules/ui/router.py

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