Avoid panic on person page for person we don't have in memory

This commit is contained in:
Mike Dilger 2023-01-17 14:16:53 +13:00
parent a4d331533e
commit 9a9f359fba

View File

@ -18,11 +18,13 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
} }
}; };
let person = maybe_person.as_ref().unwrap();
ui.add_space(24.0); ui.add_space(24.0);
ui.heading(get_name(person)); if let Some(person) = &maybe_person {
ui.heading(get_name(person));
} else {
ui.heading(&pubkeyhex.0);
}
ui.horizontal(|ui| { ui.horizontal(|ui| {
// Avatar first // Avatar first
@ -32,29 +34,32 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
app.placeholder_avatar.clone() app.placeholder_avatar.clone()
}; };
ui.image(&avatar, Vec2 { x: 36.0, y: 36.0 }); ui.image(&avatar, Vec2 { x: 36.0, y: 36.0 });
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label(RichText::new(GossipUi::hex_pubkey_short(&pubkeyhex)).weak()); ui.label(RichText::new(GossipUi::hex_pubkey_short(&pubkeyhex)).weak());
GossipUi::render_person_name_line(ui, Some(person)); GossipUi::render_person_name_line(ui, maybe_person.as_ref());
}); });
}); });
ui.add_space(12.0); ui.add_space(12.0);
if let Some(about) = person.about.as_deref() { if let Some(person) = &maybe_person {
ui.label(about); if let Some(about) = person.about.as_deref() {
ui.label(about);
}
} }
ui.add_space(12.0); ui.add_space(12.0);
#[allow(clippy::collapsible_else_if)] if let Some(person) = &maybe_person {
if person.followed == 0 { #[allow(clippy::collapsible_else_if)]
if ui.button("FOLLOW").clicked() { if maybe_person.is_none() || person.followed == 0 {
GLOBALS.people.follow(&pubkeyhex, true); if ui.button("FOLLOW").clicked() {
} GLOBALS.people.follow(&pubkeyhex, true);
} else { }
if ui.button("UNFOLLOW").clicked() { } else {
GLOBALS.people.follow(&pubkeyhex, false); if ui.button("UNFOLLOW").clicked() {
GLOBALS.people.follow(&pubkeyhex, false);
}
} }
} }