Skip to content

Commit 686f1bc

Browse files
CopilotGZTimeWalker
andcommitted
Changes before error encountered
Co-authored-by: GZTimeWalker <[email protected]>
1 parent 6ecdd40 commit 686f1bc

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

crates/wsrx-desktop-gpui/src/views/root.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
use gpui::{Context, Entity, Render, Window, div, prelude::*};
33

44
use super::{ConnectionsView, GetStartedView, NetworkLogsView, SettingsView, SidebarView};
5-
use crate::{components::title_bar::TitleBar, models::app_state::Page, styles::colors};
5+
use crate::{components::title_bar::TitleBar, models::app_state::PageId, styles::colors};
66

77
pub struct RootView {
8-
/// Current active page
9-
current_page: Page,
8+
/// Current active page (string-based: "home", "logs", "settings", "default-scope", or scope.host)
9+
current_page: PageId,
1010

1111
/// Title bar
1212
title_bar: Entity<TitleBar>,
@@ -26,11 +26,11 @@ pub struct RootView {
2626

2727
impl RootView {
2828
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
29-
let current_page = Page::GetStarted;
29+
let current_page = "home".to_string();
3030
let window_handle = window.window_handle();
3131

3232
let root = Self {
33-
current_page,
33+
current_page: current_page.clone(),
3434
show_sidebar: true,
3535
title_bar: cx.new(|_cx| TitleBar::new(window_handle.clone())),
3636
sidebar: cx.new(|cx| SidebarView::new(window, cx, current_page)),
@@ -67,7 +67,7 @@ impl RootView {
6767
root
6868
}
6969

70-
pub fn set_page(&mut self, page: Page, cx: &mut Context<Self>) {
70+
pub fn set_page(&mut self, page: PageId, cx: &mut Context<Self>) {
7171
self.current_page = page;
7272
cx.notify(); // Trigger re-render
7373
}
@@ -100,15 +100,16 @@ impl RootView {
100100
}
101101

102102
fn render_page_content(&self) -> impl IntoElement {
103+
let page = self.current_page.as_str();
103104
div()
104105
.id("page-content")
105106
.flex_1()
106107
.overflow_y_scroll() // Allow vertical scrolling when content overflows
107-
.child(match self.current_page {
108-
Page::GetStarted => div().h_full().child(self.get_started.clone()),
109-
Page::Connections => div().h_full().child(self.connections.clone()),
110-
Page::NetworkLogs => div().h_full().child(self.network_logs.clone()),
111-
Page::Settings => div().h_full().child(self.settings.clone()),
108+
.child(match page {
109+
"home" => div().h_full().child(self.get_started.clone()),
110+
"logs" => div().h_full().child(self.network_logs.clone()),
111+
"settings" => div().h_full().child(self.settings.clone()),
112+
_ => div().h_full().child(self.connections.clone()), // Scope pages show connections
112113
})
113114
}
114115
}

crates/wsrx-desktop-gpui/src/views/sidebar.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
use gpui::{App, Context, Render, SharedString, Window, div, prelude::*, svg};
33

44
use 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

1111
pub struct SidebarView {
12-
active_page: Page,
12+
active_page: PageId,
1313
on_page_change: Option<PageChangeCallback>,
1414
}
1515

1616
impl 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

Comments
 (0)