mod.rs (2510B)
1 pub mod picture; 2 pub mod preview; 3 4 use crate::ui::note::NoteOptions; 5 use egui::{ScrollArea, Widget}; 6 use enostr::Pubkey; 7 use nostrdb::{Ndb, Transaction}; 8 pub use picture::ProfilePic; 9 pub use preview::ProfilePreview; 10 11 use crate::{ 12 actionbar::NoteAction, imgcache::ImageCache, muted::MuteFun, notecache::NoteCache, 13 notes_holder::NotesHolderStorage, profile::Profile, 14 }; 15 16 use super::timeline::{tabs_ui, TimelineTabView}; 17 18 pub struct ProfileView<'a> { 19 pubkey: &'a Pubkey, 20 col_id: usize, 21 profiles: &'a mut NotesHolderStorage<Profile>, 22 note_options: NoteOptions, 23 ndb: &'a Ndb, 24 note_cache: &'a mut NoteCache, 25 img_cache: &'a mut ImageCache, 26 } 27 28 impl<'a> ProfileView<'a> { 29 pub fn new( 30 pubkey: &'a Pubkey, 31 col_id: usize, 32 profiles: &'a mut NotesHolderStorage<Profile>, 33 ndb: &'a Ndb, 34 note_cache: &'a mut NoteCache, 35 img_cache: &'a mut ImageCache, 36 note_options: NoteOptions, 37 ) -> Self { 38 ProfileView { 39 pubkey, 40 col_id, 41 profiles, 42 ndb, 43 note_cache, 44 img_cache, 45 note_options, 46 } 47 } 48 49 pub fn ui(&mut self, ui: &mut egui::Ui, is_muted: &MuteFun) -> Option<NoteAction> { 50 let scroll_id = egui::Id::new(("profile_scroll", self.col_id, self.pubkey)); 51 52 ScrollArea::vertical() 53 .id_salt(scroll_id) 54 .show(ui, |ui| { 55 let txn = Transaction::new(self.ndb).expect("txn"); 56 if let Ok(profile) = self.ndb.get_profile_by_pubkey(&txn, self.pubkey.bytes()) { 57 ProfilePreview::new(&profile, self.img_cache).ui(ui); 58 } 59 let profile = self 60 .profiles 61 .notes_holder_mutated( 62 self.ndb, 63 self.note_cache, 64 &txn, 65 self.pubkey.bytes(), 66 is_muted, 67 ) 68 .get_ptr(); 69 70 profile.timeline.selected_view = tabs_ui(ui); 71 72 let reversed = false; 73 74 TimelineTabView::new( 75 profile.timeline.current_view(), 76 reversed, 77 self.note_options, 78 &txn, 79 self.ndb, 80 self.note_cache, 81 self.img_cache, 82 ) 83 .show(ui) 84 }) 85 .inner 86 } 87 }