mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-23 11:14:19 +01:00
add unread note indicator option to NoteView
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -37,6 +37,7 @@ pub struct NoteView<'a, 'd> {
|
|||||||
framed: bool,
|
framed: bool,
|
||||||
flags: NoteOptions,
|
flags: NoteOptions,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
|
show_unread_indicator: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NoteResponse {
|
pub struct NoteResponse {
|
||||||
@@ -101,6 +102,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
flags,
|
flags,
|
||||||
framed,
|
framed,
|
||||||
jobs,
|
jobs,
|
||||||
|
show_unread_indicator: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +189,11 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unread_indicator(mut self, show_unread_indicator: bool) -> Self {
|
||||||
|
self.show_unread_indicator = show_unread_indicator;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn textmode_ui(&mut self, ui: &mut egui::Ui) -> egui::Response {
|
fn textmode_ui(&mut self, ui: &mut egui::Ui) -> egui::Response {
|
||||||
let note_key = self.note.key().expect("todo: implement non-db notes");
|
let note_key = self.note.key().expect("todo: implement non-db notes");
|
||||||
let txn = self.note.txn().expect("todo: implement non-db notes");
|
let txn = self.note.txn().expect("todo: implement non-db notes");
|
||||||
@@ -353,16 +360,33 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
note: &Note,
|
note: &Note,
|
||||||
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
||||||
|
show_unread_indicator: bool,
|
||||||
) {
|
) {
|
||||||
let note_key = note.key().unwrap();
|
let note_key = note.key().unwrap();
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
let horiz_resp = ui
|
||||||
|
.horizontal(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 2.0;
|
ui.spacing_mut().item_spacing.x = 2.0;
|
||||||
ui.add(Username::new(profile.as_ref().ok(), note.pubkey()).abbreviated(20));
|
ui.add(Username::new(profile.as_ref().ok(), note.pubkey()).abbreviated(20));
|
||||||
|
|
||||||
let cached_note = note_cache.cached_note_or_insert_mut(note_key, note);
|
let cached_note = note_cache.cached_note_or_insert_mut(note_key, note);
|
||||||
render_reltime(ui, cached_note, true);
|
render_reltime(ui, cached_note, true);
|
||||||
});
|
})
|
||||||
|
.response;
|
||||||
|
|
||||||
|
if !show_unread_indicator {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let radius = 4.0;
|
||||||
|
let circle_center = {
|
||||||
|
let mut center = horiz_resp.rect.right_center();
|
||||||
|
center.x += radius + 4.0;
|
||||||
|
center
|
||||||
|
};
|
||||||
|
|
||||||
|
ui.painter()
|
||||||
|
.circle_filled(circle_center, radius, crate::colors::PINK);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wide_ui(
|
fn wide_ui(
|
||||||
@@ -393,6 +417,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
self.note_context.note_cache,
|
self.note_context.note_cache,
|
||||||
self.note,
|
self.note,
|
||||||
profile,
|
profile,
|
||||||
|
self.show_unread_indicator,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
@@ -477,7 +502,13 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
let mut note_action: Option<NoteAction> = pfp_resp.into_action(self.note.pubkey());
|
let mut note_action: Option<NoteAction> = pfp_resp.into_action(self.note.pubkey());
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||||
NoteView::note_header(ui, self.note_context.note_cache, self.note, profile);
|
NoteView::note_header(
|
||||||
|
ui,
|
||||||
|
self.note_context.note_cache,
|
||||||
|
self.note,
|
||||||
|
profile,
|
||||||
|
self.show_unread_indicator,
|
||||||
|
);
|
||||||
ui.horizontal(|ui| 's: {
|
ui.horizontal(|ui| 's: {
|
||||||
ui.spacing_mut().item_spacing.x = 2.0;
|
ui.spacing_mut().item_spacing.x = 2.0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user