From 29f3c74d06eccf8145ed53b71fae23d080a7130a Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sun, 20 Sep 2026 09:53:39 +0700 Subject: [PATCH] update ui --- Cargo.lock | 1 + crates/workspace/Cargo.toml | 1 + crates/workspace/src/lib.rs | 24 +++++++++++++++++++++++- crates/workspace/src/sidebar/mod.rs | 15 ++++++++++++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adf6e30b..0f3ccf14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9363,6 +9363,7 @@ dependencies = [ "chat_ui", "common", "community", + "community_ui", "device", "gpui-pre", "instant", diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index 66aa4d90..34779ce4 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -13,6 +13,7 @@ device = { path = "../device" } chat = { path = "../chat" } chat_ui = { path = "../chat_ui" } community = { path = "../community" } +community_ui = { path = "../community_ui" } settings = { path = "../settings" } person = { path = "../person" } auto_update = { path = "../auto_update" } diff --git a/crates/workspace/src/lib.rs b/crates/workspace/src/lib.rs index 1658ff45..2b283300 100644 --- a/crates/workspace/src/lib.rs +++ b/crates/workspace/src/lib.rs @@ -6,6 +6,7 @@ use anyhow::Error; use auto_update::AutoUpdater; use chat::{ChatEvent, ChatRegistry}; use common::download_dir; +use community::{CommunityEvent, CommunityRegistry}; use device::{DeviceEvent, DeviceRegistry}; use gpui::prelude::FluentBuilder; use gpui::{ @@ -73,12 +74,13 @@ pub struct Workspace { /// Async tasks tasks: Vec>>, /// Event subscriptions - _subscriptions: SmallVec<[Subscription; 6]>, + _subscriptions: SmallVec<[Subscription; 7]>, } impl Workspace { fn new(window: &mut Window, cx: &mut Context) -> Self { let chat = ChatRegistry::global(cx); + let communities = CommunityRegistry::global(cx); let device = DeviceRegistry::global(cx); let nostr = NostrRegistry::global(cx); @@ -212,6 +214,26 @@ impl Workspace { }), ); + subscriptions.push( + // Observe all events emitted by the community registry + cx.subscribe_in( + &communities, + window, + move |this, communities, event, window, cx| { + if let CommunityEvent::Open(id) = event + && let Some(community) = communities.read(cx).community(id) + { + this.add_panel_to_dock( + community_ui::init(community, window, cx), + DockPlacement::Center, + window, + cx, + ); + } + }, + ), + ); + cx.defer_in(window, move |this, window, cx| { let sidebar = PanelHandle::new(sidebar); diff --git a/crates/workspace/src/sidebar/mod.rs b/crates/workspace/src/sidebar/mod.rs index b71f683c..137d6193 100644 --- a/crates/workspace/src/sidebar/mod.rs +++ b/crates/workspace/src/sidebar/mod.rs @@ -100,7 +100,12 @@ impl Sidebar { cx.notify(); } - fn open_community(&mut self, community: Entity, cx: &mut Context) { + fn open_community( + &mut self, + community: Entity, + window: &mut Window, + cx: &mut Context, + ) { let id = community.read(cx).id().to_hex(); let settings = AppSettings::global(cx); @@ -108,6 +113,10 @@ impl Sidebar { settings.record_recent_community(id, cx); }); + CommunityRegistry::global(cx).update(cx, |registry, cx| { + registry.emit_community(&community, window, cx); + }); + cx.notify(); } @@ -392,8 +401,8 @@ fn render_rows(range: Range, rows: &[SidebarRow], cx: &Context) ) .avatar(seed) .picture(picture) - .on_click(cx.listener(move |this, _event, _window, cx| { - this.open_community(community.clone(), cx); + .on_click(cx.listener(move |this, _event, window, cx| { + this.open_community(community.clone(), window, cx); })) .into_any_element() }