notedeck

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

mod.rs (2331B)


      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::NoteActionResponse, imgcache::ImageCache, 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) -> NoteActionResponse {
     50         let scroll_id = egui::Id::new(("profile_scroll", self.col_id, self.pubkey));
     51 
     52         ScrollArea::vertical()
     53             .id_source(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(self.ndb, self.note_cache, &txn, self.pubkey.bytes())
     62                     .get_ptr();
     63 
     64                 profile.timeline.selected_view = tabs_ui(ui);
     65 
     66                 let reversed = false;
     67 
     68                 TimelineTabView::new(
     69                     profile.timeline.current_view(),
     70                     reversed,
     71                     self.note_options,
     72                     &txn,
     73                     self.ndb,
     74                     self.note_cache,
     75                     self.img_cache,
     76                 )
     77                 .show(ui)
     78             })
     79             .inner
     80     }
     81 }