add profile preview and implement scrolling

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-10-11 16:36:34 -04:00
parent 44948fdff0
commit ce3f24abcd
6 changed files with 143 additions and 86 deletions

View File

@@ -1,11 +1,11 @@
pub mod picture;
pub mod preview;
use egui::{Label, RichText};
use nostrdb::Ndb;
use egui::{ScrollArea, Widget};
use enostr::Pubkey;
use nostrdb::{Ndb, Transaction};
pub use picture::ProfilePic;
pub use preview::ProfilePreview;
use tracing::info;
use crate::{
actionbar::TimelineResponse, column::Columns, imgcache::ImageCache, notecache::NoteCache,
@@ -15,6 +15,7 @@ use crate::{
use super::TimelineView;
pub struct ProfileView<'a> {
pubkey: Pubkey,
timeline_id: TimelineId,
columns: &'a mut Columns,
ndb: &'a Ndb,
@@ -24,6 +25,7 @@ pub struct ProfileView<'a> {
impl<'a> ProfileView<'a> {
pub fn new(
pubkey: Pubkey,
timeline_id: TimelineId,
columns: &'a mut Columns,
ndb: &'a Ndb,
@@ -31,6 +33,7 @@ impl<'a> ProfileView<'a> {
img_cache: &'a mut ImageCache,
) -> Self {
ProfileView {
pubkey,
timeline_id,
columns,
ndb,
@@ -40,18 +43,28 @@ impl<'a> ProfileView<'a> {
}
pub fn ui(&mut self, ui: &mut egui::Ui) -> TimelineResponse {
ui.add(Label::new(
RichText::new("PROFILE VIEW").text_style(egui::TextStyle::Heading),
));
let scroll_id = egui::Id::new(("profile_scroll", self.timeline_id, self.pubkey));
TimelineView::new(
self.timeline_id,
self.columns,
self.ndb,
self.note_cache,
self.img_cache,
false,
)
.ui(ui)
ScrollArea::vertical()
.id_source(scroll_id)
.show(ui, |ui| {
{
let txn = Transaction::new(self.ndb).expect("txn");
if let Ok(profile) = self.ndb.get_profile_by_pubkey(&txn, self.pubkey.bytes()) {
ProfilePreview::new(&profile, self.img_cache).ui(ui);
}
}
TimelineView::new(
self.timeline_id,
self.columns,
self.ndb,
self.note_cache,
self.img_cache,
false,
)
.ui_no_scroll(ui)
})
.inner
}
}