refactor: move profile_body to fn
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -76,7 +76,9 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
.get_profile_by_pubkey(&txn, self.pubkey.bytes())
|
.get_profile_by_pubkey(&txn, self.pubkey.bytes())
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if let Some(profile_view_action) = self.profile_body(ui, profile.as_ref()) {
|
if let Some(profile_view_action) =
|
||||||
|
profile_body(ui, self.pubkey, self.note_context, profile.as_ref())
|
||||||
|
{
|
||||||
action = Some(profile_view_action);
|
action = Some(profile_view_action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,10 +125,12 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
|
|
||||||
output.inner
|
output.inner
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn profile_body(
|
fn profile_body(
|
||||||
&mut self,
|
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
|
pubkey: &Pubkey,
|
||||||
|
note_context: &mut NoteContext,
|
||||||
profile: Option<&ProfileRecord<'_>>,
|
profile: Option<&ProfileRecord<'_>>,
|
||||||
) -> Option<ProfileViewAction> {
|
) -> Option<ProfileViewAction> {
|
||||||
let mut action = None;
|
let mut action = None;
|
||||||
@@ -150,16 +154,16 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.put(
|
ui.put(
|
||||||
pfp_rect,
|
pfp_rect,
|
||||||
&mut ProfilePic::new(self.note_context.img_cache, get_profile_url(profile))
|
&mut ProfilePic::new(note_context.img_cache, get_profile_url(profile))
|
||||||
.size(size)
|
.size(size)
|
||||||
.border(ProfilePic::border_stroke(ui)),
|
.border(ProfilePic::border_stroke(ui)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ui
|
if ui
|
||||||
.add(copy_key_widget(&pfp_rect, self.note_context.i18n))
|
.add(copy_key_widget(&pfp_rect, note_context.i18n))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
let to_copy = if let Some(bech) = self.pubkey.npub() {
|
let to_copy = if let Some(bech) = pubkey.npub() {
|
||||||
bech
|
bech
|
||||||
} else {
|
} else {
|
||||||
error!("Could not convert Pubkey to bech");
|
error!("Could not convert Pubkey to bech");
|
||||||
@@ -171,12 +175,12 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
ui.with_layout(Layout::right_to_left(egui::Align::RIGHT), |ui| {
|
ui.with_layout(Layout::right_to_left(egui::Align::RIGHT), |ui| {
|
||||||
ui.add_space(24.0);
|
ui.add_space(24.0);
|
||||||
|
|
||||||
let target_key = self.pubkey;
|
let target_key = pubkey;
|
||||||
let selected = self.note_context.accounts.get_selected_account();
|
let selected = note_context.accounts.get_selected_account();
|
||||||
|
|
||||||
let profile_type = if selected.key.secret_key.is_none() {
|
let profile_type = if selected.key.secret_key.is_none() {
|
||||||
ProfileType::ReadOnly
|
ProfileType::ReadOnly
|
||||||
} else if &selected.key.pubkey == self.pubkey {
|
} else if &selected.key.pubkey == pubkey {
|
||||||
ProfileType::MyProfile
|
ProfileType::MyProfile
|
||||||
} else {
|
} else {
|
||||||
ProfileType::Followable(selected.is_following(target_key.bytes()))
|
ProfileType::Followable(selected.is_following(target_key.bytes()))
|
||||||
@@ -184,10 +188,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
|
|
||||||
match profile_type {
|
match profile_type {
|
||||||
ProfileType::MyProfile => {
|
ProfileType::MyProfile => {
|
||||||
if ui
|
if ui.add(edit_profile_button(note_context.i18n)).clicked() {
|
||||||
.add(edit_profile_button(self.note_context.i18n))
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
action = Some(ProfileViewAction::EditProfile);
|
action = Some(ProfileViewAction::EditProfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +256,6 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
|
|
||||||
action
|
action
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
enum ProfileType {
|
enum ProfileType {
|
||||||
MyProfile,
|
MyProfile,
|
||||||
|
|||||||
Reference in New Issue
Block a user