consolidate timelineTab ui to TimelineTabView
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::{
|
||||
actionbar::{BarAction, TimelineResponse}, imgcache::ImageCache, notecache::NoteCache, thread::Threads, ui,
|
||||
actionbar::TimelineResponse, imgcache::ImageCache, notecache::NoteCache, thread::Threads,
|
||||
};
|
||||
use enostr::Pubkey;
|
||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||
use tracing::{error, warn};
|
||||
use tracing::error;
|
||||
|
||||
use super::timeline::TimelineTabView;
|
||||
|
||||
pub struct ThreadView<'a> {
|
||||
threads: &'a mut Threads,
|
||||
@@ -44,8 +45,6 @@ impl<'a> ThreadView<'a> {
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> TimelineResponse {
|
||||
let txn = Transaction::new(self.ndb).expect("txn");
|
||||
let mut action: Option<BarAction> = None;
|
||||
let mut open_profile = None;
|
||||
|
||||
let selected_note_key = if let Ok(key) = self
|
||||
.ndb
|
||||
@@ -72,7 +71,7 @@ impl<'a> ThreadView<'a> {
|
||||
let note = if let Ok(note) = self.ndb.get_note_by_key(&txn, selected_note_key) {
|
||||
note
|
||||
} else {
|
||||
return;
|
||||
return TimelineResponse::default();
|
||||
};
|
||||
|
||||
let root_id = {
|
||||
@@ -96,56 +95,17 @@ impl<'a> ThreadView<'a> {
|
||||
error!("Thread::poll_notes_into_view: {e}");
|
||||
}
|
||||
|
||||
let len = thread.view().notes.len();
|
||||
|
||||
thread.view().list.clone().borrow_mut().ui_custom_layout(
|
||||
ui,
|
||||
len,
|
||||
|ui, start_index| {
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
ui.spacing_mut().item_spacing.x = 4.0;
|
||||
|
||||
let ind = len - 1 - start_index;
|
||||
|
||||
let note_key = thread.view().notes[ind].key;
|
||||
|
||||
let note = if let Ok(note) = self.ndb.get_note_by_key(&txn, note_key) {
|
||||
note
|
||||
} else {
|
||||
warn!("failed to query note {:?}", note_key);
|
||||
return 0;
|
||||
};
|
||||
|
||||
ui::padding(8.0, ui, |ui| {
|
||||
let note_response =
|
||||
ui::NoteView::new(self.ndb, self.note_cache, self.img_cache, ¬e)
|
||||
.note_previews(!self.textmode)
|
||||
.textmode(self.textmode)
|
||||
.options_button(!self.textmode)
|
||||
.show(ui);
|
||||
if let Some(bar_action) = note_response.action {
|
||||
action = Some(bar_action);
|
||||
}
|
||||
if note_response.clicked_profile {
|
||||
open_profile = Some(Pubkey::new(*note.pubkey()))
|
||||
}
|
||||
|
||||
if let Some(selection) = note_response.context_selection {
|
||||
selection.process(ui, ¬e);
|
||||
}
|
||||
});
|
||||
|
||||
ui::hline(ui);
|
||||
//ui.add(egui::Separator::default().spacing(0.0));
|
||||
|
||||
1
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
TimelineResponse {
|
||||
bar_action: action,
|
||||
open_profile,
|
||||
}
|
||||
TimelineTabView::new(
|
||||
thread.view(),
|
||||
true,
|
||||
self.textmode,
|
||||
&txn,
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
)
|
||||
.show(ui)
|
||||
})
|
||||
.inner
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user