Continue redesign for the v1 stable release #5

Merged
reya merged 11 commits from redesign-2 into master 2026-02-12 08:32:17 +00:00
2 changed files with 34 additions and 34 deletions
Showing only changes of commit 9380288fc1 - Show all commits

View File

@@ -333,19 +333,18 @@ impl ChatRegistry {
/// Emit an open room event. /// Emit an open room event.
/// ///
/// If the room is new, add it to the registry. /// If the room is new, add it to the registry.
pub fn emit_room(&mut self, room: WeakEntity<Room>, cx: &mut Context<Self>) { pub fn emit_room(&mut self, room: &Entity<Room>, cx: &mut Context<Self>) {
if let Some(room) = room.upgrade() { // Get the room's ID.
let id = room.read(cx).id; let id = room.read(cx).id;
// If the room is new, add it to the registry. // If the room is new, add it to the registry.
if !self.rooms.iter().any(|r| r.read(cx).id == id) { if !self.rooms.iter().any(|r| r.read(cx).id == id) {
self.rooms.insert(0, room); self.rooms.insert(0, room.to_owned());
} }
// Emit the open room event. // Emit the open room event.
cx.emit(ChatEvent::OpenRoom(id)); cx.emit(ChatEvent::OpenRoom(id));
} }
}
/// Close a room. /// Close a room.
pub fn close_room(&mut self, id: u64, cx: &mut Context<Self>) { pub fn close_room(&mut self, id: u64, cx: &mut Context<Self>) {

View File

@@ -75,7 +75,7 @@ pub struct Sidebar {
contact_list: Entity<Option<Vec<PublicKey>>>, contact_list: Entity<Option<Vec<PublicKey>>>,
/// Async tasks /// Async tasks
tasks: SmallVec<[Task<()>; 1]>, tasks: SmallVec<[Task<Result<(), Error>>; 1]>,
/// Event subscriptions /// Event subscriptions
_subscriptions: SmallVec<[Subscription; 1]>, _subscriptions: SmallVec<[Subscription; 1]>,
@@ -118,11 +118,11 @@ impl Sidebar {
} }
} }
InputEvent::Focus => { InputEvent::Focus => {
this.set_input_focus(cx); this.set_input_focus(window, cx);
this.get_contact_list(window, cx); this.get_contact_list(window, cx);
} }
InputEvent::Blur => { InputEvent::Blur => {
this.set_input_focus(cx); this.set_input_focus(window, cx);
} }
}; };
}), }),
@@ -168,16 +168,16 @@ impl Sidebar {
Ok(contacts) => { Ok(contacts) => {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.set_contact_list(contacts, cx); this.set_contact_list(contacts, cx);
}) })?;
.ok();
} }
Err(e) => { Err(e) => {
cx.update(|window, cx| { cx.update(|window, cx| {
window.push_notification(Notification::error(e.to_string()), cx); window.push_notification(Notification::error(e.to_string()), cx);
}) })?;
.ok();
} }
}; };
Ok(())
})); }));
} }
@@ -309,7 +309,7 @@ impl Sidebar {
} }
/// Get all selected public keys in the sidebar. /// Get all selected public keys in the sidebar.
fn selected(&self, cx: &Context<Self>) -> HashSet<PublicKey> { fn get_selected(&self, cx: &Context<Self>) -> HashSet<PublicKey> {
self.selected_pkeys.read(cx).clone() self.selected_pkeys.read(cx).clone()
} }
@@ -322,26 +322,24 @@ impl Sidebar {
let signer_pkey = nostr.read(cx).signer_pkey(cx); let signer_pkey = nostr.read(cx).signer_pkey(cx);
// Get all selected public keys // Get all selected public keys
let receivers = self.selected(cx); let receivers = self.get_selected(cx);
let task: Task<Result<(), Error>> = cx.spawn_in(window, async move |this, cx| { self.tasks.push(cx.spawn_in(window, async move |this, cx| {
let public_key = signer_pkey.await?; let public_key = signer_pkey.await?;
// Create a new room and emit it
async_chat.update_in(cx, |this, _window, cx| {
let room = cx.new(|_| Room::new(public_key, receivers).kind(RoomKind::Ongoing));
this.emit_room(&room, cx);
})?;
// Reset the find panel // Reset the find panel
this.update_in(cx, |this, window, cx| { this.update_in(cx, |this, window, cx| {
this.reset(window, cx); this.reset(window, cx);
})?; })?;
// Create a new room and emit it
async_chat.update_in(cx, |this, _window, cx| {
let room = cx.new(|_| Room::new(public_key, receivers).kind(RoomKind::Ongoing));
this.emit_room(room.downgrade(), cx);
})?;
Ok(()) Ok(())
}); }));
task.detach();
} }
/// Get the active filter. /// Get the active filter.
@@ -369,11 +367,11 @@ impl Sidebar {
.enumerate() .enumerate()
.map(|(ix, item)| { .map(|(ix, item)| {
let room = item.read(cx); let room = item.read(cx);
let weak_room = item.downgrade(); let room_clone = item.clone();
let public_key = room.display_member(cx).public_key(); let public_key = room.display_member(cx).public_key();
let handler = cx.listener(move |_this, _ev, _window, cx| { let handler = cx.listener(move |_this, _ev, _window, cx| {
ChatRegistry::global(cx).update(cx, |s, cx| { ChatRegistry::global(cx).update(cx, |s, cx| {
s.emit_room(weak_room.clone(), cx); s.emit_room(&room_clone, cx);
}); });
}); });
@@ -628,12 +626,14 @@ impl Render for Sidebar {
.gap_1() .gap_1()
.overflow_y_hidden() .overflow_y_hidden()
.when(show_find_panel, |this| { .when(show_find_panel, |this| {
this.gap_2() this.gap_3()
.when_some(self.find_results.read(cx).as_ref(), |this, results| { .when_some(self.find_results.read(cx).as_ref(), |this, results| {
this.child( this.child(
v_flex() v_flex()
.gap_2() .gap_1()
.flex_1() .flex_1()
.border_b_1()
.border_color(cx.theme().border_variant)
.child( .child(
div() div()
.text_xs() .text_xs()
@@ -657,7 +657,7 @@ impl Render for Sidebar {
.when_some(self.contact_list.read(cx).as_ref(), |this, contacts| { .when_some(self.contact_list.read(cx).as_ref(), |this, contacts| {
this.child( this.child(
v_flex() v_flex()
.gap_2() .gap_1()
.flex_1() .flex_1()
.child( .child(
div() div()
@@ -708,6 +708,7 @@ impl Render for Sidebar {
.label(button_label) .label(button_label)
.primary() .primary()
.small() .small()
.shadow_lg()
.on_click(cx.listener(move |this, _ev, window, cx| { .on_click(cx.listener(move |this, _ev, window, cx| {
this.create_room(window, cx); this.create_room(window, cx);
})), })),