| |
| import gradio as gr |
| from .views import create_landing_view, create_login_view, 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): |
| 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(): |
| router = Router() |
| |
| with gr.Blocks(css="footer {display: none}") as app: |
| |
| with gr.Group(visible=True) as landing_container: |
| landing_view, start_button = create_landing_view() |
| |
| with gr.Group(visible=False) as login_container: |
| login_view, login_button = create_login_view() |
| |
| with gr.Group(visible=False) as dashboard_container: |
| dashboard_view, logout_button = create_dashboard_view() |
|
|
| |
| def handle_navigation(view_name, **kwargs): |
| return router.switch_view(view_name, **kwargs) |
|
|
| |
| start_button.click( |
| fn=lambda: handle_navigation("login"), |
| outputs=[landing_container, login_container, dashboard_container] |
| ) |
|
|
| login_button.click( |
| 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] |
| ) |
|
|
| logout_button.click( |
| fn=lambda: handle_navigation("landing"), |
| outputs=[landing_container, login_container, dashboard_container] |
| ) |
|
|
| return app |
|
|