mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Person page (click on an avatar to arrive)
This commit is contained in:
parent
739b05dd72
commit
2ff85497a9
@ -4,10 +4,10 @@ use crate::globals::{Globals, GLOBALS};
|
|||||||
use crate::ui::widgets::{CopyButton, ReplyButton};
|
use crate::ui::widgets::{CopyButton, ReplyButton};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, Color32, Context, Frame, Label, Layout, RichText, ScrollArea, Sense, TextEdit,
|
Align, Color32, Context, Frame, Image, Label, Layout, RichText, ScrollArea, Sense, TextEdit,
|
||||||
TextStyle, Ui, Vec2,
|
TextStyle, Ui, Vec2,
|
||||||
};
|
};
|
||||||
use nostr_types::{EventKind, Id};
|
use nostr_types::{EventKind, Id, PublicKey};
|
||||||
|
|
||||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui: &mut Ui) {
|
pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||||
let feed = GLOBALS.feed.blocking_lock().get();
|
let feed = GLOBALS.feed.blocking_lock().get();
|
||||||
@ -244,7 +244,15 @@ fn render_post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Avatar first
|
// Avatar first
|
||||||
ui.image(&app.placeholder_avatar, Vec2 { x: 36.0, y: 36.0 });
|
if ui
|
||||||
|
.add(
|
||||||
|
Image::new(&app.placeholder_avatar, Vec2 { x: 36.0, y: 36.0 })
|
||||||
|
.sense(Sense::click()),
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
set_person_view(app, event.pubkey);
|
||||||
|
};
|
||||||
|
|
||||||
// Everything else next
|
// Everything else next
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
@ -343,3 +351,16 @@ fn render_post(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_person_view(app: &mut GossipUi, pubkey: PublicKey) {
|
||||||
|
if let Some(dbperson) = GLOBALS.people.blocking_read().get(&pubkey).cloned() {
|
||||||
|
app.person_view_name = if let Some(name) = &dbperson.name {
|
||||||
|
Some(name.to_string())
|
||||||
|
} else {
|
||||||
|
Some(GossipUi::pubkey_short(&pubkey))
|
||||||
|
};
|
||||||
|
app.person_view_person = Some(dbperson);
|
||||||
|
app.person_view_pubkey = Some(pubkey);
|
||||||
|
app.page = Page::Person;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ mod widgets;
|
|||||||
mod you;
|
mod you;
|
||||||
|
|
||||||
use crate::about::About;
|
use crate::about::About;
|
||||||
|
use crate::db::DbPerson;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::globals::GLOBALS;
|
use crate::globals::GLOBALS;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
@ -52,6 +53,7 @@ enum Page {
|
|||||||
Feed,
|
Feed,
|
||||||
PeopleFollow,
|
PeopleFollow,
|
||||||
PeopleList,
|
PeopleList,
|
||||||
|
Person,
|
||||||
You,
|
You,
|
||||||
Relays,
|
Relays,
|
||||||
Settings,
|
Settings,
|
||||||
@ -77,6 +79,9 @@ struct GossipUi {
|
|||||||
import_hex: String,
|
import_hex: String,
|
||||||
replying_to: Option<Id>,
|
replying_to: Option<Id>,
|
||||||
hides: Vec<Id>,
|
hides: Vec<Id>,
|
||||||
|
person_view_pubkey: Option<PublicKey>,
|
||||||
|
person_view_person: Option<DbPerson>,
|
||||||
|
person_view_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for GossipUi {
|
impl Drop for GossipUi {
|
||||||
@ -144,6 +149,9 @@ impl GossipUi {
|
|||||||
import_hex: "".to_owned(),
|
import_hex: "".to_owned(),
|
||||||
replying_to: None,
|
replying_to: None,
|
||||||
hides: Vec::new(),
|
hides: Vec::new(),
|
||||||
|
person_view_pubkey: None,
|
||||||
|
person_view_person: None,
|
||||||
|
person_view_name: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,6 +199,7 @@ impl eframe::App for GossipUi {
|
|||||||
Page::Feed => feed::update(self, ctx, frame, ui),
|
Page::Feed => feed::update(self, ctx, frame, ui),
|
||||||
Page::PeopleList => people::update(self, ctx, frame, ui),
|
Page::PeopleList => people::update(self, ctx, frame, ui),
|
||||||
Page::PeopleFollow => people::update(self, ctx, frame, ui),
|
Page::PeopleFollow => people::update(self, ctx, frame, ui),
|
||||||
|
Page::Person => people::update(self, ctx, frame, ui),
|
||||||
Page::You => you::update(self, ctx, frame, ui),
|
Page::You => you::update(self, ctx, frame, ui),
|
||||||
Page::Relays => relays::update(self, ctx, frame, ui),
|
Page::Relays => relays::update(self, ctx, frame, ui),
|
||||||
Page::Settings => settings::update(self, ctx, frame, ui, darkmode),
|
Page::Settings => settings::update(self, ctx, frame, ui, darkmode),
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use super::{GossipUi, Page};
|
use super::{GossipUi, Page};
|
||||||
use crate::comms::BusMessage;
|
use crate::comms::BusMessage;
|
||||||
|
use crate::db::DbPerson;
|
||||||
use crate::globals::GLOBALS;
|
use crate::globals::GLOBALS;
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::{Context, RichText, ScrollArea, TextEdit, TopBottomPanel, Ui, Vec2};
|
use egui::{Context, Image, RichText, ScrollArea, Sense, TextEdit, TopBottomPanel, Ui, Vec2};
|
||||||
|
use nostr_types::PublicKey;
|
||||||
|
|
||||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||||
TopBottomPanel::top("people_menu").show(ctx, |ui| {
|
TopBottomPanel::top("people_menu").show(ctx, |ui| {
|
||||||
@ -11,6 +13,10 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
ui.selectable_value(&mut app.page, Page::PeopleFollow, "Follow Someone New");
|
ui.selectable_value(&mut app.page, Page::PeopleFollow, "Follow Someone New");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
if let Some(name) = &app.person_view_name {
|
||||||
|
ui.selectable_value(&mut app.page, Page::Person, name);
|
||||||
|
ui.separator();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -124,7 +130,15 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// Avatar first
|
// Avatar first
|
||||||
ui.image(&app.placeholder_avatar, Vec2 { x: 36.0, y: 36.0 });
|
if ui
|
||||||
|
.add(
|
||||||
|
Image::new(&app.placeholder_avatar, Vec2 { x: 36.0, y: 36.0 })
|
||||||
|
.sense(Sense::click()),
|
||||||
|
)
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
set_person_view(app, person);
|
||||||
|
};
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak());
|
ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak());
|
||||||
@ -143,14 +157,63 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
|
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
|
|
||||||
if let Some(about) = person.about.as_deref() {
|
|
||||||
ui.label(about);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.add_space(12.0);
|
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if app.page == Page::Person {
|
||||||
|
if app.person_view_pubkey.is_none()
|
||||||
|
|| app.person_view_person.is_none()
|
||||||
|
|| app.person_view_name.is_none()
|
||||||
|
{
|
||||||
|
ui.label("ERROR");
|
||||||
|
} else {
|
||||||
|
//let pubkey = app.person_view_pubkey.as_ref().unwrap();
|
||||||
|
let person = app.person_view_person.as_ref().unwrap();
|
||||||
|
let name = app.person_view_name.as_ref().unwrap();
|
||||||
|
|
||||||
|
ui.add_space(24.0);
|
||||||
|
|
||||||
|
ui.heading(name);
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
// Avatar first
|
||||||
|
ui.image(&app.placeholder_avatar, Vec2 { x: 36.0, y: 36.0 });
|
||||||
|
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
ui.label(RichText::new(GossipUi::hex_pubkey_short(&person.pubkey)).weak());
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label(RichText::new(person.name.as_deref().unwrap_or("")).strong());
|
||||||
|
|
||||||
|
ui.add_space(24.0);
|
||||||
|
|
||||||
|
if let Some(dns_id) = person.dns_id.as_deref() {
|
||||||
|
ui.label(dns_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(12.0);
|
||||||
|
|
||||||
|
if let Some(about) = person.about.as_deref() {
|
||||||
|
ui.label(about);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.add_space(12.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_person_view(app: &mut GossipUi, person: &DbPerson) {
|
||||||
|
if let Ok(pk) = PublicKey::try_from_hex_string(&person.pubkey) {
|
||||||
|
app.person_view_pubkey = Some(pk);
|
||||||
|
app.person_view_person = Some(person.clone());
|
||||||
|
app.person_view_name = if let Some(name) = &person.name {
|
||||||
|
Some(name.to_string())
|
||||||
|
} else {
|
||||||
|
Some(GossipUi::pubkey_short(&pk))
|
||||||
|
};
|
||||||
|
app.page = Page::Person;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user