refactor panel open flow

This commit is contained in:
2026-09-23 08:53:20 +07:00
parent 6510e45e4e
commit 7ba289440b
9 changed files with 122 additions and 191 deletions
+32 -22
View File
@@ -2,7 +2,7 @@ use std::ops::Range;
use std::rc::Rc;
use auto_update::AutoUpdater;
use chat::{ChatEvent, ChatRegistry, RoomKind};
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
use common::TimestampExt;
use community::{ChannelId, Community, CommunityEvent, CommunityRegistry};
use gpui::prelude::FluentBuilder;
@@ -20,7 +20,7 @@ use state::NostrRegistry;
use theme::{ActiveTheme, TABBAR_HEIGHT};
use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariants};
use ui::dock::{Panel, PanelEvent};
use ui::dock::{DockArea, DockPlacement, Panel, PanelEvent, PanelHandle};
use ui::indicator::Indicator;
use ui::menu::{DropdownMenu, PopupMenuItem};
use ui::nav_item::NavItem;
@@ -46,6 +46,8 @@ pub struct Sidebar {
scroll_handles: [UniformListScrollHandle; 3],
/// Scroll state of the channel and member lists
community_scroll: ScrollHandle,
/// The dock the sidebar opens its panels in
dock: WeakEntity<DockArea>,
active_tab: SidebarTab,
/// The community the sidebar is browsing, if any
community: Option<WeakEntity<Community>>,
@@ -59,7 +61,7 @@ pub struct Sidebar {
}
impl Sidebar {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
pub fn new(window: &mut Window, dock: WeakEntity<DockArea>, cx: &mut Context<Self>) -> Self {
let chat = ChatRegistry::global(cx);
let communities = CommunityRegistry::global(cx);
let nostr = NostrRegistry::global(cx);
@@ -98,6 +100,7 @@ impl Sidebar {
UniformListScrollHandle::new(),
],
community_scroll: ScrollHandle::default(),
dock,
active_tab: SidebarTab::Recents,
community: None,
channels_open: true,
@@ -130,25 +133,34 @@ impl Sidebar {
settings.record_recent_community(id, cx);
});
CommunityRegistry::global(cx).update(cx, |registry, cx| {
registry.emit_community(&community, window, cx);
});
self.community = Some(community.downgrade());
ui::dock::add_panel_to(
&self.dock,
PanelHandle::new(community_ui::init(community, window, cx)),
DockPlacement::Center,
window,
cx,
);
cx.notify();
}
fn close_community(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(community) = self.community.take() else {
fn open_room(&mut self, room: Entity<Room>, window: &mut Window, cx: &mut Context<Self>) {
ui::dock::add_panel_to(
&self.dock,
PanelHandle::new(chat_ui::init(room.downgrade(), window, cx)),
DockPlacement::Center,
window,
cx,
);
}
/// Leave the community view, returning the sidebar to its tab list.
fn reset_community(&mut self, cx: &mut Context<Self>) {
if self.community.take().is_none() {
return;
};
if let Ok(id) = community.read_with(cx, |community, _cx| community.id()) {
CommunityRegistry::global(cx).update(cx, |registry, cx| {
registry.emit_close(id, window, cx);
});
}
cx.notify();
}
@@ -250,8 +262,8 @@ impl Sidebar {
.tooltip("Back")
.ghost()
.small()
.on_click(cx.listener(|this, _event, window, cx| {
this.close_community(window, cx);
.on_click(cx.listener(|this, _event, _window, cx| {
this.reset_community(cx);
})),
);
}
@@ -407,10 +419,8 @@ fn render_rows(range: Range<usize>, rows: &[SidebarRow], cx: &Context<Sidebar>)
let created_at = room.read(cx).created_at.to_ago();
let room_clone = room.clone();
let handler = cx.listener(move |_this, _event, window, cx| {
ChatRegistry::global(cx).update(cx, |chat, cx| {
chat.emit_room(&room_clone, window, cx);
});
let handler = cx.listener(move |this, _event, window, cx| {
this.open_room(room_clone.clone(), window, cx);
});
TreeRow::new(