threads: ensure we always handle bar results
We were not handling it in ThreadView, now we do. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{timeline::TimelineSource, ui, Damus};
|
||||
use crate::{actionbar::BarResult, timeline::TimelineSource, ui, Damus};
|
||||
use nostrdb::{NoteKey, Transaction};
|
||||
use std::collections::HashSet;
|
||||
use tracing::warn;
|
||||
@@ -18,8 +18,9 @@ impl<'a> ThreadView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<BarResult> {
|
||||
let txn = Transaction::new(&self.app.ndb).expect("txn");
|
||||
let mut result: Option<BarResult> = None;
|
||||
|
||||
let selected_note_key = if let Ok(key) = self
|
||||
.app
|
||||
@@ -30,7 +31,7 @@ impl<'a> ThreadView<'a> {
|
||||
key
|
||||
} else {
|
||||
// TODO: render 404 ?
|
||||
return;
|
||||
return None;
|
||||
};
|
||||
|
||||
let scroll_id = egui::Id::new((
|
||||
@@ -118,7 +119,10 @@ impl<'a> ThreadView<'a> {
|
||||
.show(ui);
|
||||
|
||||
if let Some(action) = resp.action {
|
||||
action.execute(self.app, self.timeline, note.id(), &txn);
|
||||
let br = action.execute(self.app, self.timeline, note.id(), &txn);
|
||||
if br.is_some() {
|
||||
result = br;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -128,5 +132,7 @@ impl<'a> ThreadView<'a> {
|
||||
1
|
||||
});
|
||||
});
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,13 @@ fn timeline_ui(ui: &mut egui::Ui, app: &mut Damus, timeline: usize, reversed: bo
|
||||
let view = app.timelines[timeline].current_view();
|
||||
let len = view.notes.len();
|
||||
let mut bar_result: Option<BarResult> = None;
|
||||
let txn = if let Ok(txn) = Transaction::new(&app.ndb) {
|
||||
txn
|
||||
} else {
|
||||
warn!("failed to create transaction");
|
||||
return 0;
|
||||
};
|
||||
|
||||
view.list
|
||||
.clone()
|
||||
.borrow_mut()
|
||||
@@ -72,13 +79,6 @@ fn timeline_ui(ui: &mut egui::Ui, app: &mut Damus, timeline: usize, reversed: bo
|
||||
|
||||
let note_key = app.timelines[timeline].current_view().notes[ind].key;
|
||||
|
||||
let txn = if let Ok(txn) = Transaction::new(&app.ndb) {
|
||||
txn
|
||||
} else {
|
||||
warn!("failed to create transaction for {:?}", note_key);
|
||||
return 0;
|
||||
};
|
||||
|
||||
let note = if let Ok(note) = app.ndb.get_note_by_key(&txn, note_key) {
|
||||
note
|
||||
} else {
|
||||
@@ -111,12 +111,17 @@ fn timeline_ui(ui: &mut egui::Ui, app: &mut Damus, timeline: usize, reversed: bo
|
||||
if let Some(br) = bar_result {
|
||||
match br {
|
||||
// update the thread for next render if we have new notes
|
||||
BarResult::NewThreadNotes(notes) => {
|
||||
let view = app.timelines[timeline].current_view_mut();
|
||||
view.insert(¬es);
|
||||
BarResult::NewThreadNotes(new_notes) => {
|
||||
let thread = app
|
||||
.threads
|
||||
.thread_mut(&app.ndb, &txn, new_notes.root_id.bytes())
|
||||
.get_ptr();
|
||||
new_notes.process(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user