From 311af51beecaef9140fb95c82cd2a24596e2b28f Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 20 Jan 2026 18:35:20 +0700 Subject: [PATCH] wip --- crates/coop/src/main.rs | 4 +- .../coop/src/{chatspace.rs => workspace.rs} | 37 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) rename crates/coop/src/{chatspace.rs => workspace.rs} (96%) diff --git a/crates/coop/src/main.rs b/crates/coop/src/main.rs index 6fe4ec0..903d912 100644 --- a/crates/coop/src/main.rs +++ b/crates/coop/src/main.rs @@ -12,12 +12,12 @@ use ui::Root; use crate::actions::Quit; mod actions; -mod chatspace; mod login; mod new_identity; mod sidebar; mod user; mod views; +mod workspace; fn main() { // Initialize logging @@ -111,7 +111,7 @@ fn main() { auto_update::init(cx); // Root Entity - Root::new(chatspace::init(window, cx).into(), window, cx) + Root::new(workspace::init(window, cx).into(), window, cx) }) }) .expect("Failed to open window. Please restart the application."); diff --git a/crates/coop/src/chatspace.rs b/crates/coop/src/workspace.rs similarity index 96% rename from crates/coop/src/chatspace.rs rename to crates/coop/src/workspace.rs index 6ae1e2b..fea0fc7 100644 --- a/crates/coop/src/chatspace.rs +++ b/crates/coop/src/workspace.rs @@ -31,30 +31,30 @@ use crate::actions::{ use crate::user::viewer; use crate::views::compose::compose_button; use crate::views::{preferences, setup_relay, welcome}; -use crate::{login, sidebar, user}; +use crate::{sidebar, user}; -pub fn init(window: &mut Window, cx: &mut App) -> Entity { - cx.new(|cx| ChatSpace::new(window, cx)) +pub fn init(window: &mut Window, cx: &mut App) -> Entity { + cx.new(|cx| Workspace::new(window, cx)) } #[derive(Debug)] -pub struct ChatSpace { +pub struct Workspace { /// App's Title Bar title_bar: Entity, /// App's Dock Area dock: Entity, - /// Determines if the chat space is ready to use - ready: bool, - /// Event subscriptions - _subscriptions: SmallVec<[Subscription; 3]>, + _subscriptions: SmallVec<[Subscription; 4]>, } -impl ChatSpace { +impl Workspace { fn new(window: &mut Window, cx: &mut Context) -> Self { let chat = ChatRegistry::global(cx); + let nostr = NostrRegistry::global(cx); + let identity = nostr.read(cx).identity(); + let title_bar = cx.new(|_| TitleBar::new()); let dock = cx.new(|cx| DockArea::new(window, cx)); @@ -67,6 +67,17 @@ impl ChatSpace { }), ); + subscriptions.push( + // Observe the identity entity + cx.observe_in(&identity, window, move |this, state, window, cx| { + if state.read(cx).has_public_key() { + this.dock.update(cx, |this, cx| { + this.toggle_dock(DockPlacement::Left, window, cx); + }); + }; + }), + ); + subscriptions.push( // Observe all events emitted by the chat registry cx.subscribe_in(&chat, window, move |this, chat, ev, window, cx| { @@ -87,6 +98,7 @@ impl ChatSpace { this.dock.update(cx, |this, cx| { // Force focus to the tab panel this.focus_tab_panel(window, cx); + // Dispatch the close panel action cx.defer_in(window, |_, window, cx| { window.dispatch_action(Box::new(ClosePanel), cx); @@ -118,7 +130,6 @@ impl ChatSpace { Self { dock, title_bar, - ready: false, _subscriptions: subscriptions, } } @@ -147,7 +158,7 @@ impl ChatSpace { // Update the dock layout self.dock.update(cx, |this, cx| { - this.set_left_dock(left, Some(px(DEFAULT_SIDEBAR_WIDTH)), true, window, cx); + this.set_left_dock(left, Some(px(DEFAULT_SIDEBAR_WIDTH)), false, window, cx); this.set_center(center, window, cx); }); } @@ -483,7 +494,7 @@ impl ChatSpace { } } -impl Render for ChatSpace { +impl Render for Workspace { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { let modal_layer = Root::render_modal_layer(window, cx); let notification_layer = Root::render_notification_layer(window, cx); @@ -496,7 +507,7 @@ impl Render for ChatSpace { }); div() - .id(SharedString::from("chatspace")) + .id(SharedString::from("workspace")) .on_action(cx.listener(Self::on_settings)) .on_action(cx.listener(Self::on_profile)) .on_action(cx.listener(Self::on_relays))