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())
|
||||
.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);
|
||||
}
|
||||
|
||||
@@ -123,10 +125,12 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
||||
|
||||
output.inner
|
||||
}
|
||||
}
|
||||
|
||||
fn profile_body(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
pubkey: &Pubkey,
|
||||
note_context: &mut NoteContext,
|
||||
profile: Option<&ProfileRecord<'_>>,
|
||||
) -> Option<ProfileViewAction> {
|
||||
let mut action = None;
|
||||
@@ -150,16 +154,16 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
||||
ui.horizontal(|ui| {
|
||||
ui.put(
|
||||
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)
|
||||
.border(ProfilePic::border_stroke(ui)),
|
||||
);
|
||||
|
||||
if ui
|
||||
.add(copy_key_widget(&pfp_rect, self.note_context.i18n))
|
||||
.add(copy_key_widget(&pfp_rect, note_context.i18n))
|
||||
.clicked()
|
||||
{
|
||||
let to_copy = if let Some(bech) = self.pubkey.npub() {
|
||||
let to_copy = if let Some(bech) = pubkey.npub() {
|
||||
bech
|
||||
} else {
|
||||
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.add_space(24.0);
|
||||
|
||||
let target_key = self.pubkey;
|
||||
let selected = self.note_context.accounts.get_selected_account();
|
||||
let target_key = pubkey;
|
||||
let selected = note_context.accounts.get_selected_account();
|
||||
|
||||
let profile_type = if selected.key.secret_key.is_none() {
|
||||
ProfileType::ReadOnly
|
||||
} else if &selected.key.pubkey == self.pubkey {
|
||||
} else if &selected.key.pubkey == pubkey {
|
||||
ProfileType::MyProfile
|
||||
} else {
|
||||
ProfileType::Followable(selected.is_following(target_key.bytes()))
|
||||
@@ -184,10 +188,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
||||
|
||||
match profile_type {
|
||||
ProfileType::MyProfile => {
|
||||
if ui
|
||||
.add(edit_profile_button(self.note_context.i18n))
|
||||
.clicked()
|
||||
{
|
||||
if ui.add(edit_profile_button(note_context.i18n)).clicked() {
|
||||
action = Some(ProfileViewAction::EditProfile);
|
||||
}
|
||||
}
|
||||
@@ -255,7 +256,6 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
||||
|
||||
action
|
||||
}
|
||||
}
|
||||
|
||||
enum ProfileType {
|
||||
MyProfile,
|
||||
|
||||
Reference in New Issue
Block a user