This commit is contained in:
2026-09-19 18:14:18 +07:00
parent b8f8737dc5
commit bd8bff4693
6 changed files with 95 additions and 46 deletions
+13 -22
View File
@@ -67,14 +67,10 @@ enum Command {
}
pub struct Workspace {
sidebar: Entity<Sidebar>,
/// App's Dock Area
dock: Entity<DockArea>,
title_bar_chrome: Rc<dock::TitleBarChrome>,
/// Async tasks
tasks: Vec<Task<Result<(), Error>>>,
/// Event subscriptions
_subscriptions: SmallVec<[Subscription; 6]>,
}
@@ -221,17 +217,25 @@ impl Workspace {
}),
);
cx.defer_in(window, |this, window, cx| {
cx.defer_in(window, move |this, window, cx| {
let sidebar = PanelHandle::new(sidebar);
this.dock.update(cx, |area, cx| {
let left = DockLayout::tabs().panel_view(Arc::new(sidebar), cx);
area.set_dock(DockPlacement::Left, left, window, cx);
area.set_dock_size(DockPlacement::Left, SIDEBAR_WIDTH, window, cx);
});
let greeter = PanelHandle::new(greeter::init(window, cx));
let center = DockLayout::v_split()
.child(DockLayout::tabs().panel_view(Arc::new(greeter), cx), None);
this.dock
.update(cx, |area, cx| area.set_center(center, window, cx));
this.dock.update(cx, |area, cx| {
area.set_center(center, window, cx);
});
});
Self {
sidebar,
dock,
title_bar_chrome,
tasks: vec![],
@@ -725,20 +729,7 @@ impl Render for Workspace {
.on_action(cx.listener(Self::on_command))
.relative()
.size_full()
.child(
h_flex()
.size_full()
.child(
div()
.flex_shrink_0()
.h_full()
.w(SIDEBAR_WIDTH)
.border_r_1()
.border_color(cx.theme().border_variant)
.child(self.sidebar.clone()),
)
.child(self.dock.clone()),
)
.child(self.dock.clone())
// Notifications
.children(notification_layer)
// Modals
+5 -2
View File
@@ -157,8 +157,11 @@ impl Render for GreeterPanel {
.label("Change theme")
.ghost()
.small()
.on_click(cx.listener(move |_, _, _, cx| {
cx.dispatch_action(&Command::ToggleTheme);
.on_click(cx.listener(move |_, _, window, cx| {
window.dispatch_action(
Box::new(Command::ToggleTheme),
cx,
);
})),
),
),
+23 -17
View File
@@ -368,14 +368,6 @@ impl Sidebar {
.when(cfg!(target_os = "macos"), |this| {
this.pl(px(TRAFFIC_LIGHT_PADDING))
})
.when_none(&current_user, |this| {
this.child(
div()
.text_xs()
.text_color(cx.theme().text_muted)
.child(SharedString::from("Import your identity to continue")),
)
})
.when_some(current_user.as_ref(), |this, public_key| {
let persons = PersonRegistry::global(cx);
let profile = persons.read(cx).get(public_key, cx);
@@ -468,6 +460,18 @@ impl Panel for Sidebar {
fn panel_id(&self) -> SharedString {
"Sidebar".into()
}
fn title(&self, _cx: &App) -> AnyElement {
SharedString::from("Sidebar").into_any_element()
}
fn closable(&self, _cx: &App) -> bool {
false
}
fn zoomable(&self, _cx: &App) -> bool {
false
}
}
impl EventEmitter<PanelEvent> for Sidebar {}
@@ -493,16 +497,18 @@ impl Render for Sidebar {
.image_cache(retain_all("sidebar"))
.size_full()
.gap_2()
.bg(cx.theme().surface_background)
.border_r_1()
.border_color(cx.theme().border_variant)
.child(self.render_user(window, cx))
.child(
v_flex()
.px_2()
.py_1()
.gap_1()
.child(
NavItem::new("nav-inbox", "Inbox", Icon::new(IconName::Inbox).small())
.on_click(|_event, _window, cx| {
cx.dispatch_action(&Command::ShowInbox)
.on_click(|_event, window, cx| {
window.dispatch_action(Box::new(Command::ShowInbox), cx)
}),
)
.child(
@@ -516,27 +522,27 @@ impl Render for Sidebar {
})
.on_click({
let sidebar = sidebar.clone();
move |_event, _window, cx| {
move |_event, window, cx| {
if let Err(error) = sidebar.update(cx, |this, cx| {
this.new_requests = false;
cx.notify();
}) {
log::error!("Failed to clear new requests: {error}");
}
cx.dispatch_action(&Command::ShowRequests);
window.dispatch_action(Box::new(Command::ShowRequests), cx);
}
}),
)
.child(
NavItem::new("nav-browse", "Browse", Icon::new(IconName::Compass).small())
.on_click(|_event, _window, cx| {
cx.dispatch_action(&Command::ShowBrowse)
.on_click(|_event, window, cx| {
window.dispatch_action(Box::new(Command::ShowBrowse), cx)
}),
)
.child(
NavItem::new("nav-search", "Search", Icon::new(IconName::Search).small())
.on_click(|_event, _window, cx| {
cx.dispatch_action(&Command::ShowSearch)
.on_click(|_event, window, cx| {
window.dispatch_action(Box::new(Command::ShowSearch), cx)
}),
),
)