create_convo.rs (1837B)
1 use egui::{Label, RichText}; 2 use enostr::Pubkey; 3 use nostrdb::{Ndb, Transaction}; 4 use notedeck::{tr, ContactState, Images, Localization, MediaJobSender, NotedeckTextStyle}; 5 use notedeck_ui::{contacts_list::ContactsCollection, ContactsListView}; 6 7 pub struct CreateConvoUi<'a> { 8 ndb: &'a Ndb, 9 jobs: &'a MediaJobSender, 10 img_cache: &'a mut Images, 11 contacts: &'a ContactState, 12 i18n: &'a mut Localization, 13 } 14 15 pub struct CreateConvoResponse { 16 pub recipient: Pubkey, 17 } 18 19 impl<'a> CreateConvoUi<'a> { 20 pub fn new( 21 ndb: &'a Ndb, 22 jobs: &'a MediaJobSender, 23 img_cache: &'a mut Images, 24 contacts: &'a ContactState, 25 i18n: &'a mut Localization, 26 ) -> Self { 27 Self { 28 ndb, 29 jobs, 30 img_cache, 31 contacts, 32 i18n, 33 } 34 } 35 36 pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<CreateConvoResponse> { 37 let ContactState::Received { contacts, .. } = self.contacts else { 38 // TODO render something about not having contacts 39 return None; 40 }; 41 42 let txn = Transaction::new(self.ndb).expect("txn"); 43 44 ui.add(Label::new( 45 RichText::new(tr!( 46 self.i18n, 47 "Contacts", 48 "Heading shown when choosing a contact to start a new chat" 49 )) 50 .text_style(NotedeckTextStyle::Heading.text_style()), 51 )); 52 let resp = ContactsListView::new( 53 ContactsCollection::Set(contacts), 54 self.jobs, 55 self.ndb, 56 self.img_cache, 57 &txn, 58 ) 59 .ui(ui); 60 61 resp.output.map(|a| match a { 62 notedeck_ui::ContactsListAction::Select(pubkey) => { 63 CreateConvoResponse { recipient: pubkey } 64 } 65 }) 66 } 67 }