NoteActionResponse for note preview pfp clicking
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::actionbar::BarAction;
|
use crate::actionbar::NoteActionResponse;
|
||||||
use crate::images::ImageType;
|
use crate::images::ImageType;
|
||||||
use crate::imgcache::ImageCache;
|
use crate::imgcache::ImageCache;
|
||||||
use crate::notecache::NoteCache;
|
use crate::notecache::NoteCache;
|
||||||
@@ -17,7 +17,7 @@ pub struct NoteContents<'a> {
|
|||||||
note: &'a Note<'a>,
|
note: &'a Note<'a>,
|
||||||
note_key: NoteKey,
|
note_key: NoteKey,
|
||||||
options: NoteOptions,
|
options: NoteOptions,
|
||||||
action: Option<BarAction>,
|
action: NoteActionResponse,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> NoteContents<'a> {
|
impl<'a> NoteContents<'a> {
|
||||||
@@ -38,12 +38,12 @@ impl<'a> NoteContents<'a> {
|
|||||||
note,
|
note,
|
||||||
note_key,
|
note_key,
|
||||||
options,
|
options,
|
||||||
action: None,
|
action: NoteActionResponse::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn action(&self) -> Option<BarAction> {
|
pub fn action(&self) -> &NoteActionResponse {
|
||||||
self.action
|
&self.action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ fn render_note_contents(
|
|||||||
let note_action = if let Some((id, block_str)) = inline_note {
|
let note_action = if let Some((id, block_str)) = inline_note {
|
||||||
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, block_str).action
|
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, block_str).action
|
||||||
} else {
|
} else {
|
||||||
None
|
NoteActionResponse::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
if !images.is_empty() && !options.has_textmode() {
|
if !images.is_empty() && !options.has_textmode() {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub use quote_repost::QuoteRepostView;
|
|||||||
pub use reply::PostReplyView;
|
pub use reply::PostReplyView;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
actionbar::BarAction,
|
actionbar::{BarAction, NoteActionResponse},
|
||||||
app_style::NotedeckTextStyle,
|
app_style::NotedeckTextStyle,
|
||||||
colors,
|
colors,
|
||||||
imgcache::ImageCache,
|
imgcache::ImageCache,
|
||||||
@@ -22,7 +22,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use egui::emath::{pos2, Vec2};
|
use egui::emath::{pos2, Vec2};
|
||||||
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
|
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
|
||||||
use enostr::NoteId;
|
use enostr::{NoteId, Pubkey};
|
||||||
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
||||||
|
|
||||||
use super::profile::preview::{get_display_name, one_line_display_name_widget};
|
use super::profile::preview::{get_display_name, one_line_display_name_widget};
|
||||||
@@ -37,37 +37,27 @@ pub struct NoteView<'a> {
|
|||||||
|
|
||||||
pub struct NoteResponse {
|
pub struct NoteResponse {
|
||||||
pub response: egui::Response,
|
pub response: egui::Response,
|
||||||
pub action: Option<BarAction>,
|
|
||||||
pub context_selection: Option<NoteContextSelection>,
|
pub context_selection: Option<NoteContextSelection>,
|
||||||
pub clicked_profile: bool,
|
pub action: NoteActionResponse,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NoteResponse {
|
impl NoteResponse {
|
||||||
pub fn new(response: egui::Response) -> Self {
|
pub fn new(response: egui::Response) -> Self {
|
||||||
Self {
|
Self {
|
||||||
response,
|
response,
|
||||||
action: None,
|
|
||||||
context_selection: None,
|
context_selection: None,
|
||||||
clicked_profile: false,
|
action: NoteActionResponse::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_action(self, action: Option<BarAction>) -> Self {
|
pub fn with_action(mut self, action: NoteActionResponse) -> Self {
|
||||||
Self { action, ..self }
|
self.action = action;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_option(self, context_selection: Option<NoteContextSelection>) -> Self {
|
pub fn select_option(mut self, context_selection: Option<NoteContextSelection>) -> Self {
|
||||||
Self {
|
self.context_selection = context_selection;
|
||||||
context_selection,
|
self
|
||||||
..self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn click_profile(self, clicked_profile: bool) -> Self {
|
|
||||||
Self {
|
|
||||||
clicked_profile,
|
|
||||||
..self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,8 +431,11 @@ impl<'a> NoteView<'a> {
|
|||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
let note_key = self.note.key().expect("todo: support non-db notes");
|
let note_key = self.note.key().expect("todo: support non-db notes");
|
||||||
let txn = self.note.txn().expect("todo: support non-db notes");
|
let txn = self.note.txn().expect("todo: support non-db notes");
|
||||||
let mut note_action: Option<BarAction> = None;
|
|
||||||
|
let mut open_profile: Option<Pubkey> = None;
|
||||||
|
let mut bar_action: Option<BarAction> = None;
|
||||||
let mut selected_option: Option<NoteContextSelection> = None;
|
let mut selected_option: Option<NoteContextSelection> = None;
|
||||||
|
|
||||||
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
|
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||||
let maybe_hitbox = maybe_note_hitbox(ui, note_key);
|
let maybe_hitbox = maybe_note_hitbox(ui, note_key);
|
||||||
let container_right = {
|
let container_right = {
|
||||||
@@ -452,12 +445,12 @@ impl<'a> NoteView<'a> {
|
|||||||
Pos2::new(x, y)
|
Pos2::new(x, y)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut clicked_profile = false;
|
|
||||||
|
|
||||||
// wide design
|
// wide design
|
||||||
let response = if self.options().has_wide() {
|
let response = if self.options().has_wide() {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
clicked_profile = self.pfp(note_key, &profile, ui).clicked();
|
if self.pfp(note_key, &profile, ui).clicked() {
|
||||||
|
open_profile = Some(Pubkey::new(*self.note.pubkey()));
|
||||||
|
};
|
||||||
|
|
||||||
let size = ui.available_size();
|
let size = ui.available_size();
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
@@ -500,18 +493,21 @@ impl<'a> NoteView<'a> {
|
|||||||
self.options(),
|
self.options(),
|
||||||
);
|
);
|
||||||
let resp = ui.add(&mut contents);
|
let resp = ui.add(&mut contents);
|
||||||
note_action = note_action.or(contents.action());
|
bar_action = bar_action.or(contents.action().bar_action);
|
||||||
|
open_profile = open_profile.or(contents.action().open_profile);
|
||||||
|
|
||||||
if self.options().has_actionbar() {
|
if self.options().has_actionbar() {
|
||||||
let ab = render_note_actionbar(ui, self.note.id(), note_key);
|
let ab = render_note_actionbar(ui, self.note.id(), note_key);
|
||||||
note_action = note_action.or(ab.inner);
|
bar_action = bar_action.or(ab.inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
resp
|
resp
|
||||||
} else {
|
} else {
|
||||||
// main design
|
// main design
|
||||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||||
clicked_profile = self.pfp(note_key, &profile, ui).clicked();
|
if self.pfp(note_key, &profile, ui).clicked() {
|
||||||
|
open_profile = Some(Pubkey::new(*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| {
|
||||||
selected_option = NoteView::note_header(
|
selected_option = NoteView::note_header(
|
||||||
@@ -547,30 +543,33 @@ impl<'a> NoteView<'a> {
|
|||||||
self.options(),
|
self.options(),
|
||||||
);
|
);
|
||||||
ui.add(&mut contents);
|
ui.add(&mut contents);
|
||||||
note_action = note_action.or(contents.action());
|
bar_action = bar_action.or(contents.action().bar_action);
|
||||||
|
open_profile = open_profile.or(contents.action().open_profile);
|
||||||
|
|
||||||
if self.options().has_actionbar() {
|
if self.options().has_actionbar() {
|
||||||
let ab = render_note_actionbar(ui, self.note.id(), note_key);
|
let ab = render_note_actionbar(ui, self.note.id(), note_key);
|
||||||
note_action = note_action.or(ab.inner);
|
bar_action = bar_action.or(ab.inner);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
};
|
};
|
||||||
|
|
||||||
note_action = check_note_hitbox(
|
bar_action = check_note_hitbox(
|
||||||
ui,
|
ui,
|
||||||
self.note.id(),
|
self.note.id(),
|
||||||
note_key,
|
note_key,
|
||||||
&response,
|
&response,
|
||||||
maybe_hitbox,
|
maybe_hitbox,
|
||||||
note_action,
|
bar_action,
|
||||||
);
|
);
|
||||||
|
|
||||||
NoteResponse::new(response)
|
NoteResponse::new(response)
|
||||||
.with_action(note_action)
|
.with_action(NoteActionResponse {
|
||||||
|
bar_action,
|
||||||
|
open_profile,
|
||||||
|
})
|
||||||
.select_option(selected_option)
|
.select_option(selected_option)
|
||||||
.click_profile(clicked_profile)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
use crate::actionbar::NoteActionResponse;
|
use crate::actionbar::{BarAction, NoteActionResponse};
|
||||||
use crate::timeline::TimelineTab;
|
use crate::timeline::TimelineTab;
|
||||||
use crate::{
|
use crate::{
|
||||||
actionbar::BarAction, column::Columns, imgcache::ImageCache, notecache::NoteCache,
|
column::Columns, imgcache::ImageCache, notecache::NoteCache, timeline::TimelineId, ui,
|
||||||
timeline::TimelineId, ui,
|
|
||||||
};
|
};
|
||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::{Direction, Layout};
|
use egui::{Direction, Layout};
|
||||||
use egui_tabs::TabColor;
|
use egui_tabs::TabColor;
|
||||||
use enostr::Pubkey;
|
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{error, warn};
|
||||||
|
|
||||||
pub struct TimelineView<'a> {
|
pub struct TimelineView<'a> {
|
||||||
timeline_id: TimelineId,
|
timeline_id: TimelineId,
|
||||||
@@ -277,20 +275,12 @@ impl<'a> TimelineTabView<'a> {
|
|||||||
.options_button(true)
|
.options_button(true)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
|
|
||||||
if let Some(ba) = resp.action {
|
bar_action = bar_action.or(resp.action.bar_action);
|
||||||
bar_action = Some(ba);
|
open_profile = open_profile.or(resp.action.open_profile);
|
||||||
} else if resp.response.clicked() {
|
|
||||||
debug!("clicked note");
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(context) = resp.context_selection {
|
if let Some(context) = resp.context_selection {
|
||||||
context.process(ui, ¬e);
|
context.process(ui, ¬e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.clicked_profile {
|
|
||||||
info!("clicked profile");
|
|
||||||
open_profile = Some(Pubkey::new(*note.pubkey()))
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ui::hline(ui);
|
ui::hline(ui);
|
||||||
|
|||||||
Reference in New Issue
Block a user