22use gpui:: { App , Context , Render , SharedString , Window , div, prelude:: * , svg} ;
33
44use crate :: {
5- models:: app_state:: Page ,
5+ models:: app_state:: PageId ,
66 styles:: { border_radius, colors, heights, padding, sizes, spacing} ,
77} ;
88
9- type PageChangeCallback = Box < dyn Fn ( Page , & mut App ) + Send + Sync > ;
9+ type PageChangeCallback = Box < dyn Fn ( PageId , & mut App ) + Send + Sync > ;
1010
1111pub struct SidebarView {
12- active_page : Page ,
12+ active_page : PageId ,
1313 on_page_change : Option < PageChangeCallback > ,
1414}
1515
1616impl SidebarView {
17- pub fn new ( _window : & mut Window , _cx : & mut Context < Self > , active_page : Page ) -> Self {
17+ pub fn new ( _window : & mut Window , _cx : & mut Context < Self > , active_page : PageId ) -> Self {
1818 Self {
1919 active_page,
2020 on_page_change : None ,
@@ -26,22 +26,17 @@ impl SidebarView {
2626 }
2727
2828 #[ allow( dead_code) ] // Intended for future use
29- pub fn set_active_page ( & mut self , page : Page ) {
29+ pub fn set_active_page ( & mut self , page : PageId ) {
3030 self . active_page = page;
3131 }
3232
3333 fn render_tab (
34- & self , page : Page , icon_path : & ' static str , cx : & mut Context < Self > ,
34+ & self , page_id : & str , label : & str , icon_path : & ' static str , cx : & mut Context < Self > ,
3535 ) -> impl IntoElement {
36- let is_active = self . active_page == page;
37- let label_text = match page {
38- Page :: GetStarted => t ! ( "get_started" ) ,
39- Page :: Connections => t ! ( "connections" ) ,
40- Page :: NetworkLogs => t ! ( "network_logs" ) ,
41- Page :: Settings => t ! ( "settings" ) ,
42- } ;
36+ let is_active = self . active_page == page_id;
37+ let page_id_owned = page_id. to_string ( ) ;
4338
44- let id = SharedString :: from ( format ! ( "sidebar-tab-{:? }" , page ) ) ;
39+ let id = SharedString :: from ( format ! ( "sidebar-tab-{}" , page_id ) ) ;
4540
4641 div ( )
4742 . id ( id)
@@ -65,10 +60,10 @@ impl SidebarView {
6560 } )
6661 . on_click ( cx. listener ( move |this, _event, _window, cx| {
6762 // Update our own state first
68- this. active_page = page ;
63+ this. active_page = page_id_owned . clone ( ) ;
6964 // Then notify parent
7065 if let Some ( ref callback) = this. on_page_change {
71- callback ( page , cx) ;
66+ callback ( page_id_owned . clone ( ) , cx) ;
7267 }
7368 } ) )
7469 . child (
@@ -90,7 +85,7 @@ impl SidebarView {
9085 } else {
9186 gpui:: FontWeight :: NORMAL
9287 } )
93- . child ( label_text . to_string ( ) ) ,
88+ . child ( label . to_string ( ) ) ,
9489 )
9590 }
9691}
@@ -114,13 +109,12 @@ impl Render for SidebarView {
114109 . bg ( colors:: layer_1 ( ) )
115110 . border_r_1 ( )
116111 . border_color ( colors:: element_border ( ) )
117- . child ( self . render_tab ( Page :: GetStarted , "icons/home.svg" , cx) )
118- . child ( self . render_tab ( Page :: Connections , "icons/globe-star.svg" , cx) )
119- . child ( self . render_tab ( Page :: NetworkLogs , "icons/code.svg" , cx) )
112+ . child ( self . render_tab ( "home" , t ! ( "get_started" ) , "icons/home.svg" , cx) )
113+ . child ( self . render_tab ( "logs" , t ! ( "network_logs" ) , "icons/code.svg" , cx) )
120114 . child (
121115 // Spacer
122116 div ( ) . flex_1 ( ) ,
123117 )
124- . child ( self . render_tab ( Page :: Settings , "icons/settings.svg" , cx) )
118+ . child ( self . render_tab ( "settings" , t ! ( "settings" ) , "icons/settings.svg" , cx) )
125119 }
126120}
0 commit comments