notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 3e92f868c7b7272d38efea7270ccbd82e8144cb5
parent 89a2e5f6732fab76ccc0d1bdeb8d6e81d299fb0f
Author: kernelkind <kernelkind@gmail.com>
Date:   Thu, 11 Dec 2025 12:54:14 -0600

refactor(ContactsListView): move to notedeck_ui crate

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck_columns/src/nav.rs | 6+++---
Dcrates/notedeck_columns/src/ui/profile/contacts_list.rs | 96-------------------------------------------------------------------------------
Mcrates/notedeck_columns/src/ui/profile/mod.rs | 2--
Acrates/notedeck_ui/src/contacts_list.rs | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcrates/notedeck_ui/src/lib.rs | 2++
5 files changed, 101 insertions(+), 101 deletions(-)

diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs @@ -41,7 +41,7 @@ use notedeck::{ get_current_default_msats, nav::DragResponse, tr, ui::is_narrow, Accounts, AppContext, NoteAction, NoteCache, NoteContext, RelayAction, }; -use notedeck_ui::NoteOptions; +use notedeck_ui::{ContactsListAction, ContactsListView, NoteOptions}; use tracing::error; /// The result of processing a nav response @@ -999,10 +999,10 @@ fn render_nav_body( (txn, contacts) }; - crate::ui::profile::ContactsListView::new(pubkey, contacts, &mut note_context, &txn) + ContactsListView::new(pubkey, contacts, &mut note_context, &txn) .ui(ui) .map_output(|action| match action { - crate::ui::profile::ContactsListAction::OpenProfile(pk) => { + ContactsListAction::OpenProfile(pk) => { RenderNavAction::NoteAction(NoteAction::Profile(pk)) } }) diff --git a/crates/notedeck_columns/src/ui/profile/contacts_list.rs b/crates/notedeck_columns/src/ui/profile/contacts_list.rs @@ -1,96 +0,0 @@ -use egui::{RichText, Sense}; -use enostr::Pubkey; -use nostrdb::Transaction; -use notedeck::{name::get_display_name, profile::get_profile_url, DragResponse, NoteContext}; -use notedeck_ui::ProfilePic; - -pub struct ContactsListView<'a, 'd, 'txn> { - contacts: Vec<Pubkey>, - note_context: &'a mut NoteContext<'d>, - txn: &'txn Transaction, -} - -#[derive(Clone)] -pub enum ContactsListAction { - OpenProfile(Pubkey), -} - -impl<'a, 'd, 'txn> ContactsListView<'a, 'd, 'txn> { - pub fn new( - _pubkey: &'a Pubkey, - contacts: Vec<Pubkey>, - note_context: &'a mut NoteContext<'d>, - txn: &'txn Transaction, - ) -> Self { - ContactsListView { - contacts, - note_context, - txn, - } - } - - pub fn ui(&mut self, ui: &mut egui::Ui) -> DragResponse<ContactsListAction> { - let mut action = None; - - egui::ScrollArea::vertical().show(ui, |ui| { - let clip_rect = ui.clip_rect(); - - for contact_pubkey in &self.contacts { - let (rect, resp) = - ui.allocate_exact_size(egui::vec2(ui.available_width(), 56.0), Sense::click()); - - if !clip_rect.intersects(rect) { - continue; - } - - let profile = self - .note_context - .ndb - .get_profile_by_pubkey(self.txn, contact_pubkey.bytes()) - .ok(); - - let display_name = get_display_name(profile.as_ref()); - let name_str = display_name.display_name.unwrap_or("Anonymous"); - let profile_url = get_profile_url(profile.as_ref()); - - let resp = resp.on_hover_cursor(egui::CursorIcon::PointingHand); - - if resp.hovered() { - ui.painter() - .rect_filled(rect, 0.0, ui.visuals().widgets.hovered.weak_bg_fill); - } - - let mut child_ui = ui.new_child(egui::UiBuilder::new().max_rect(rect)); - child_ui.horizontal(|ui| { - ui.add_space(16.0); - - ui.add( - &mut ProfilePic::new( - self.note_context.img_cache, - self.note_context.jobs, - profile_url, - ) - .size(48.0), - ); - - ui.add_space(12.0); - - ui.add( - egui::Label::new( - RichText::new(name_str) - .size(16.0) - .color(ui.visuals().text_color()), - ) - .selectable(false), - ); - }); - - if resp.clicked() { - action = Some(ContactsListAction::OpenProfile(*contact_pubkey)); - } - } - }); - - DragResponse::output(action) - } -} diff --git a/crates/notedeck_columns/src/ui/profile/mod.rs b/crates/notedeck_columns/src/ui/profile/mod.rs @@ -1,7 +1,5 @@ -pub mod contacts_list; pub mod edit; -pub use contacts_list::{ContactsListAction, ContactsListView}; pub use edit::EditProfileView; use egui::{vec2, Color32, CornerRadius, Layout, Rect, RichText, ScrollArea, Sense, Stroke}; use enostr::Pubkey; diff --git a/crates/notedeck_ui/src/contacts_list.rs b/crates/notedeck_ui/src/contacts_list.rs @@ -0,0 +1,96 @@ +use crate::ProfilePic; +use egui::{RichText, Sense}; +use enostr::Pubkey; +use nostrdb::Transaction; +use notedeck::{name::get_display_name, profile::get_profile_url, DragResponse, NoteContext}; + +pub struct ContactsListView<'a, 'd, 'txn> { + contacts: Vec<Pubkey>, + note_context: &'a mut NoteContext<'d>, + txn: &'txn Transaction, +} + +#[derive(Clone)] +pub enum ContactsListAction { + OpenProfile(Pubkey), +} + +impl<'a, 'd, 'txn> ContactsListView<'a, 'd, 'txn> { + pub fn new( + _pubkey: &'a Pubkey, + contacts: Vec<Pubkey>, + note_context: &'a mut NoteContext<'d>, + txn: &'txn Transaction, + ) -> Self { + ContactsListView { + contacts, + note_context, + txn, + } + } + + pub fn ui(&mut self, ui: &mut egui::Ui) -> DragResponse<ContactsListAction> { + let mut action = None; + + egui::ScrollArea::vertical().show(ui, |ui| { + let clip_rect = ui.clip_rect(); + + for contact_pubkey in &self.contacts { + let (rect, resp) = + ui.allocate_exact_size(egui::vec2(ui.available_width(), 56.0), Sense::click()); + + if !clip_rect.intersects(rect) { + continue; + } + + let profile = self + .note_context + .ndb + .get_profile_by_pubkey(self.txn, contact_pubkey.bytes()) + .ok(); + + let display_name = get_display_name(profile.as_ref()); + let name_str = display_name.display_name.unwrap_or("Anonymous"); + let profile_url = get_profile_url(profile.as_ref()); + + let resp = resp.on_hover_cursor(egui::CursorIcon::PointingHand); + + if resp.hovered() { + ui.painter() + .rect_filled(rect, 0.0, ui.visuals().widgets.hovered.weak_bg_fill); + } + + let mut child_ui = ui.new_child(egui::UiBuilder::new().max_rect(rect)); + child_ui.horizontal(|ui| { + ui.add_space(16.0); + + ui.add( + &mut ProfilePic::new( + self.note_context.img_cache, + self.note_context.jobs, + profile_url, + ) + .size(48.0), + ); + + ui.add_space(12.0); + + ui.add( + egui::Label::new( + RichText::new(name_str) + .size(16.0) + .color(ui.visuals().text_color()), + ) + .selectable(false), + ); + }); + + if resp.clicked() { + action = Some(ContactsListAction::OpenProfile(*contact_pubkey)); + } + } + }); + + DragResponse::output(action) + } +} diff --git a/crates/notedeck_ui/src/lib.rs b/crates/notedeck_ui/src/lib.rs @@ -2,6 +2,7 @@ pub mod anim; pub mod app_images; pub mod colors; pub mod constants; +pub mod contacts_list; pub mod context_menu; pub mod debug; pub mod icons; @@ -15,6 +16,7 @@ mod username; pub mod widgets; pub use anim::{rolling_number, AnimationHelper, PulseAlpha}; +pub use contacts_list::{ContactsListAction, ContactsListView}; pub use debug::debug_slider; pub use icons::{expanding_button, ICON_EXPANSION_MULTIPLE, ICON_WIDTH}; pub use mention::Mention;