refactor DisplayName -> NostrName
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::actionbar::NoteAction;
|
||||
use crate::ui;
|
||||
use crate::{actionbar::NoteAction, profile::get_display_name};
|
||||
use egui::Sense;
|
||||
use enostr::Pubkey;
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
@@ -79,12 +79,7 @@ fn mention_ui(
|
||||
ui.horizontal(|ui| {
|
||||
let profile = ndb.get_profile_by_pubkey(txn, pk).ok();
|
||||
|
||||
let name: String =
|
||||
if let Some(name) = profile.as_ref().and_then(crate::profile::get_profile_name) {
|
||||
format!("@{}", name.username())
|
||||
} else {
|
||||
"@???".to_string()
|
||||
};
|
||||
let name: String = format!("@{}", get_display_name(profile.as_ref()).name());
|
||||
|
||||
let resp = ui.add(
|
||||
egui::Label::new(egui::RichText::new(name).color(link_color).size(size))
|
||||
|
||||
@@ -16,6 +16,7 @@ pub use reply_description::reply_desc;
|
||||
|
||||
use crate::{
|
||||
actionbar::NoteAction,
|
||||
profile::get_display_name,
|
||||
ui::{self, View},
|
||||
};
|
||||
|
||||
@@ -25,7 +26,7 @@ use enostr::{NoteId, Pubkey};
|
||||
use nostrdb::{Ndb, Note, NoteKey, Transaction};
|
||||
use notedeck::{CachedNote, ImageCache, NoteCache, NotedeckTextStyle};
|
||||
|
||||
use super::profile::{get_display_name, preview::one_line_display_name_widget};
|
||||
use super::profile::preview::one_line_display_name_widget;
|
||||
|
||||
pub struct NoteView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
pub mod picture;
|
||||
pub mod preview;
|
||||
|
||||
use crate::profile::get_display_name;
|
||||
use crate::ui::note::NoteOptions;
|
||||
use crate::{colors, images};
|
||||
use crate::{notes_holder::NotesHolder, DisplayName};
|
||||
use crate::{notes_holder::NotesHolder, NostrName};
|
||||
use egui::load::TexturePoll;
|
||||
use egui::{Label, RichText, ScrollArea, Sense};
|
||||
use enostr::Pubkey;
|
||||
@@ -131,43 +132,42 @@ impl<'a> ProfileView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn display_name_widget(
|
||||
display_name: DisplayName<'_>,
|
||||
add_placeholder_space: bool,
|
||||
) -> impl egui::Widget + '_ {
|
||||
move |ui: &mut egui::Ui| match display_name {
|
||||
DisplayName::One(n) => {
|
||||
let name_response = ui.add(
|
||||
Label::new(RichText::new(n).text_style(NotedeckTextStyle::Heading3.text_style()))
|
||||
.selectable(false),
|
||||
);
|
||||
if add_placeholder_space {
|
||||
ui.add_space(16.0);
|
||||
}
|
||||
name_response
|
||||
}
|
||||
|
||||
DisplayName::Both {
|
||||
display_name,
|
||||
username,
|
||||
} => {
|
||||
fn display_name_widget(name: NostrName<'_>, add_placeholder_space: bool) -> impl egui::Widget + '_ {
|
||||
move |ui: &mut egui::Ui| -> egui::Response {
|
||||
let disp_resp = name.display_name.map(|disp_name| {
|
||||
ui.add(
|
||||
Label::new(
|
||||
RichText::new(display_name)
|
||||
.text_style(NotedeckTextStyle::Heading3.text_style()),
|
||||
RichText::new(disp_name).text_style(NotedeckTextStyle::Heading3.text_style()),
|
||||
)
|
||||
.selectable(false),
|
||||
);
|
||||
|
||||
)
|
||||
});
|
||||
let username_resp = name.username.map(|username| {
|
||||
ui.add(
|
||||
Label::new(
|
||||
RichText::new(format!("@{}", username))
|
||||
.size(12.0)
|
||||
.size(16.0)
|
||||
.color(colors::MID_GRAY),
|
||||
)
|
||||
.selectable(false),
|
||||
)
|
||||
});
|
||||
|
||||
let resp = if let Some(disp_resp) = disp_resp {
|
||||
if let Some(username_resp) = username_resp {
|
||||
username_resp
|
||||
} else {
|
||||
disp_resp
|
||||
}
|
||||
} else {
|
||||
ui.add(Label::new(RichText::new(name.name())))
|
||||
};
|
||||
|
||||
if add_placeholder_space {
|
||||
ui.add_space(16.0);
|
||||
}
|
||||
|
||||
resp
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,14 +179,6 @@ pub fn get_profile_url<'a>(profile: Option<&ProfileRecord<'a>>) -> &'a str {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_display_name<'a>(profile: Option<&ProfileRecord<'a>>) -> DisplayName<'a> {
|
||||
if let Some(name) = profile.and_then(|p| crate::profile::get_profile_name(p)) {
|
||||
name
|
||||
} else {
|
||||
DisplayName::One("??")
|
||||
}
|
||||
}
|
||||
|
||||
fn about_section_widget<'a, 'b>(profile: &'b ProfileRecord<'a>) -> impl egui::Widget + 'b
|
||||
where
|
||||
'b: 'a,
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::ui::ProfilePic;
|
||||
use crate::DisplayName;
|
||||
use crate::NostrName;
|
||||
use egui::{Frame, Label, RichText, Widget};
|
||||
use egui_extras::Size;
|
||||
use enostr::{NoteId, Pubkey};
|
||||
use nostrdb::{Ndb, ProfileRecord, Transaction};
|
||||
use nostrdb::ProfileRecord;
|
||||
|
||||
use notedeck::{ImageCache, NotedeckTextStyle, UserAccount};
|
||||
|
||||
@@ -175,22 +174,17 @@ pub fn get_account_url<'a>(
|
||||
|
||||
pub fn one_line_display_name_widget<'a>(
|
||||
visuals: &egui::Visuals,
|
||||
display_name: DisplayName<'a>,
|
||||
display_name: NostrName<'a>,
|
||||
style: NotedeckTextStyle,
|
||||
) -> impl egui::Widget + 'a {
|
||||
let text_style = style.text_style();
|
||||
let color = visuals.noninteractive().fg_stroke.color;
|
||||
|
||||
move |ui: &mut egui::Ui| match display_name {
|
||||
DisplayName::One(n) => ui.label(RichText::new(n).text_style(text_style).color(color)),
|
||||
|
||||
DisplayName::Both {
|
||||
display_name,
|
||||
username: _,
|
||||
} => ui.label(
|
||||
RichText::new(display_name)
|
||||
move |ui: &mut egui::Ui| -> egui::Response {
|
||||
ui.label(
|
||||
RichText::new(display_name.name())
|
||||
.text_style(text_style)
|
||||
.color(color),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user