/ src / stores / router.rs
router.rs
 1  use crate::layouts::*;
 2  use gpui::*;
 3  use std::collections::HashMap;
 4  
 5  #[derive(Debug, PartialEq, Eq, Hash)]
 6  pub enum Route {
 7    Auth,
 8    App,
 9  }
10  
11  pub struct Router {
12    pub current: Route,
13  }
14  
15  impl Router {
16    /// Create the views HashMap.
17    pub fn create(window: &mut Window, cx: &mut App) -> HashMap<Route, AnyView> {
18      let mut views = HashMap::new();
19  
20      views.insert(Route::Auth, cx.new(|cx| AuthView::new(window, cx)).into());
21      views.insert(Route::App, cx.new(|cx| AppView::new(window, cx)).into());
22  
23      views
24    }
25  }
26  
27  impl Global for Router {}
28  
29  pub fn init(cx: &mut App, initial: Route) {
30    cx.set_global(Router { current: initial });
31  }