diff --git a/crates/coop/src/chatspace.rs b/crates/coop/src/chatspace.rs index 7b48427..5e01263 100644 --- a/crates/coop/src/chatspace.rs +++ b/crates/coop/src/chatspace.rs @@ -1231,7 +1231,7 @@ impl ChatSpace { this.child( h_flex() .id("downloading") - .px_4() + .px_2() .h_6() .gap_1() .text_xs() @@ -1434,7 +1434,7 @@ impl Render for ChatSpace { // Only render titlebar child elements if user is logged in if registry.identity.is_some() { - let profile = Registry::read_global(cx).identity(cx); + let profile = registry.identity(cx); let left_side = self .render_titlebar_left_side(window, cx) @@ -1457,9 +1457,7 @@ impl Render for ChatSpace { .relative() .size_full() .child( - div() - .flex() - .flex_col() + v_flex() .size_full() // Title Bar .child(self.title_bar.clone()) diff --git a/crates/coop/src/main.rs b/crates/coop/src/main.rs index c04b93c..a9422fb 100644 --- a/crates/coop/src/main.rs +++ b/crates/coop/src/main.rs @@ -79,6 +79,9 @@ fn main() { // Open a window with default options cx.open_window(opts, |window, cx| { + // Bring the app to the foreground + cx.activate(true); + // Automatically sync theme with system appearance window .observe_window_appearance(|window, cx| { @@ -88,7 +91,6 @@ fn main() { // Root Entity cx.new(|cx| { - cx.activate(true); // Initialize the tokio runtime gpui_tokio::init(cx); diff --git a/crates/coop/src/views/chat/mod.rs b/crates/coop/src/views/chat/mod.rs index 57c7b9a..ecd9ead 100644 --- a/crates/coop/src/views/chat/mod.rs +++ b/crates/coop/src/views/chat/mod.rs @@ -6,7 +6,7 @@ use gpui::prelude::FluentBuilder; use gpui::{ div, img, list, px, red, relative, rems, svg, white, Action, AnyElement, App, AppContext, ClipboardItem, Context, Element, Entity, EventEmitter, Flatten, FocusHandle, Focusable, - InteractiveElement, IntoElement, ListAlignment, ListState, MouseButton, ObjectFit, + InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton, ObjectFit, ParentElement, PathPromptOptions, Render, RetainAllImageCache, SharedString, StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, Window, }; @@ -139,7 +139,7 @@ impl Chat { match signal { RoomSignal::NewMessage((gift_wrap_id, event)) => { if !this.is_sent_by_coop(gift_wrap_id) { - this.insert_message(event, cx); + this.insert_message(event, false, cx); } } RoomSignal::Refresh => { @@ -258,11 +258,7 @@ impl Chat { cx.defer_in(window, |this, window, cx| { // Optimistically update message list - this.insert_message(temp_message, cx); - - // Scroll to reveal the new message - this.list_state - .scroll_to_reveal_item(this.messages.len() + 1); + this.insert_message(temp_message, true, cx); // Remove all replies this.remove_all_replies(cx); @@ -341,7 +337,7 @@ impl Chat { } /// Convert and insert a nostr event into the chat panel - fn insert_message(&mut self, event: E, _cx: &mut Context) + fn insert_message(&mut self, event: E, scroll: bool, cx: &mut Context) where E: Into, { @@ -350,13 +346,21 @@ impl Chat { // Extend the messages list with the new events if self.messages.insert(Message::user(event)) { self.list_state.splice(old_len..old_len, 1); + + if scroll { + self.list_state.scroll_to(ListOffset { + item_ix: self.list_state.item_count(), + offset_in_item: px(0.0), + }); + cx.notify(); + } } } /// Convert and insert a vector of nostr events into the chat panel fn insert_messages(&mut self, events: Vec, cx: &mut Context) { for event in events.into_iter() { - self.insert_message(event, cx); + self.insert_message(event, false, cx); } cx.notify(); } diff --git a/crates/coop/src/views/sidebar/mod.rs b/crates/coop/src/views/sidebar/mod.rs index 9276bc4..7e95d00 100644 --- a/crates/coop/src/views/sidebar/mod.rs +++ b/crates/coop/src/views/sidebar/mod.rs @@ -656,6 +656,7 @@ impl Render for Sidebar { }) }) .small() + .cta() .bold() .secondary() .rounded(ButtonRounded::Full) @@ -676,6 +677,7 @@ impl Render for Sidebar { }) }) .small() + .cta() .bold() .secondary() .rounded(ButtonRounded::Full) diff --git a/crates/ui/src/button.rs b/crates/ui/src/button.rs index 08f1839..3b73e84 100644 --- a/crates/ui/src/button.rs +++ b/crates/ui/src/button.rs @@ -1,8 +1,8 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ div, relative, AnyElement, App, ClickEvent, Div, ElementId, Hsla, InteractiveElement, - IntoElement, MouseButton, ParentElement, RenderOnce, SharedString, - StatefulInteractiveElement as _, Styled, Window, + IntoElement, MouseButton, ParentElement, RenderOnce, SharedString, Stateful, + StatefulInteractiveElement as _, StyleRefinement, Styled, Window, }; use theme::ActiveTheme; @@ -121,8 +121,8 @@ type OnClick = Option> /// A Button element. #[derive(IntoElement)] pub struct Button { - pub base: Div, - id: ElementId, + base: Stateful
, + style: StyleRefinement, icon: Option, label: Option, @@ -156,8 +156,8 @@ impl From