mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Ui Feed pages enum change
This commit is contained in:
parent
2a5644f5d5
commit
3956aa29cb
@ -20,48 +20,43 @@ struct FeedPostParams {
|
||||
|
||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let mut feed_kind = GLOBALS.feed.get_feed_kind();
|
||||
app.page = match feed_kind {
|
||||
FeedKind::General => Page::FeedGeneral,
|
||||
FeedKind::Replies => Page::FeedReplies,
|
||||
FeedKind::Thread(_) => Page::FeedThread,
|
||||
FeedKind::Person(_) => Page::FeedPerson,
|
||||
};
|
||||
app.page = Page::Feed(feed_kind.clone());
|
||||
|
||||
// Feed Page Selection
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add(SelectableLabel::new(
|
||||
app.page == Page::FeedGeneral,
|
||||
app.page == Page::Feed(FeedKind::General),
|
||||
"Following",
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
app.page = Page::FeedGeneral;
|
||||
GLOBALS.feed.set_feed_to_general();
|
||||
feed_kind = FeedKind::General;
|
||||
app.page = Page::Feed(feed_kind.clone());
|
||||
GLOBALS.feed.set_feed_to_general();
|
||||
GLOBALS.events.clear_new();
|
||||
}
|
||||
ui.separator();
|
||||
if ui
|
||||
.add(SelectableLabel::new(
|
||||
app.page == Page::FeedReplies,
|
||||
app.page == Page::Feed(FeedKind::Replies),
|
||||
"Replies",
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
app.page = Page::FeedReplies;
|
||||
GLOBALS.feed.set_feed_to_replies();
|
||||
feed_kind = FeedKind::Replies;
|
||||
app.page = Page::Feed(feed_kind.clone());
|
||||
GLOBALS.feed.set_feed_to_replies();
|
||||
GLOBALS.events.clear_new();
|
||||
}
|
||||
if matches!(feed_kind, FeedKind::Thread(..)) {
|
||||
if matches!(feed_kind.clone(), FeedKind::Thread(..)) {
|
||||
ui.separator();
|
||||
ui.selectable_value(&mut app.page, Page::FeedThread, "Thread");
|
||||
ui.selectable_value(&mut app.page, Page::Feed(feed_kind.clone()), "Thread");
|
||||
GLOBALS.events.clear_new();
|
||||
}
|
||||
if matches!(feed_kind, FeedKind::Person(..)) {
|
||||
ui.separator();
|
||||
ui.selectable_value(&mut app.page, Page::FeedPerson, "Person");
|
||||
ui.selectable_value(&mut app.page, Page::Feed(feed_kind.clone()), "Person");
|
||||
GLOBALS.events.clear_new();
|
||||
}
|
||||
});
|
||||
@ -482,7 +477,7 @@ fn render_post_actual(
|
||||
let nam = format!("replies to #{}", GossipUi::hex_id_short(&idhex));
|
||||
if ui.link(&nam).clicked() {
|
||||
GLOBALS.feed.set_feed_to_thread(irt);
|
||||
app.page = Page::FeedThread;
|
||||
app.page = Page::Feed(FeedKind::Thread(irt));
|
||||
};
|
||||
ui.reset_style();
|
||||
}
|
||||
@ -497,7 +492,7 @@ fn render_post_actual(
|
||||
ui.menu_button(RichText::new("≡").size(28.0), |ui| {
|
||||
if !is_main_event && ui.button("View Thread").clicked() {
|
||||
GLOBALS.feed.set_feed_to_thread(event.id);
|
||||
app.page = Page::FeedThread;
|
||||
app.page = Page::Feed(FeedKind::Thread(event.id));
|
||||
}
|
||||
if ui.button("Copy ID").clicked() {
|
||||
ui.output().copied_text = event.id.as_hex_string();
|
||||
@ -515,7 +510,7 @@ fn render_post_actual(
|
||||
if !is_main_event && ui.button("➤").on_hover_text("View Thread").clicked()
|
||||
{
|
||||
GLOBALS.feed.set_feed_to_thread(event.id);
|
||||
app.page = Page::FeedThread;
|
||||
app.page = Page::Feed(FeedKind::Thread(event.id));
|
||||
}
|
||||
|
||||
ui.label(
|
||||
@ -637,7 +632,7 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: ®ex::Regex, event:
|
||||
let nam = format!("#{}", GossipUi::hex_id_short(&idhex));
|
||||
if ui.link(&nam).clicked() {
|
||||
GLOBALS.feed.set_feed_to_thread(*id);
|
||||
app.page = Page::FeedThread;
|
||||
app.page = Page::Feed(FeedKind::Thread(*id));
|
||||
};
|
||||
}
|
||||
Tag::Hashtag(s) => {
|
||||
@ -662,8 +657,7 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: ®ex::Regex, event:
|
||||
}
|
||||
|
||||
fn set_person_view(app: &mut GossipUi, pubkeyhex: &PublicKeyHex) {
|
||||
app.person_view_pubkey = Some(pubkeyhex.to_owned());
|
||||
app.page = Page::Person;
|
||||
app.page = Page::Person(pubkeyhex.to_owned());
|
||||
}
|
||||
|
||||
fn thin_red_separator(ui: &mut Ui) {
|
||||
|
@ -10,6 +10,7 @@ mod you;
|
||||
use crate::about::About;
|
||||
use crate::db::DbPerson;
|
||||
use crate::error::Error;
|
||||
use crate::feed::FeedKind;
|
||||
use crate::globals::GLOBALS;
|
||||
use crate::settings::Settings;
|
||||
use crate::ui::widgets::CopyButton;
|
||||
@ -54,13 +55,10 @@ pub fn run() -> Result<(), Error> {
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Page {
|
||||
FeedGeneral,
|
||||
FeedReplies,
|
||||
FeedThread,
|
||||
FeedPerson,
|
||||
Feed(FeedKind),
|
||||
PeopleList,
|
||||
PeopleFollow,
|
||||
Person,
|
||||
Person(PublicKeyHex),
|
||||
You,
|
||||
Relays,
|
||||
Settings,
|
||||
@ -88,7 +86,6 @@ struct GossipUi {
|
||||
import_priv: String,
|
||||
import_pub: String,
|
||||
replying_to: Option<Id>,
|
||||
person_view_pubkey: Option<PublicKeyHex>,
|
||||
avatars: HashMap<PublicKeyHex, TextureHandle>,
|
||||
new_relay_url: String,
|
||||
tag_re: regex::Regex,
|
||||
@ -145,7 +142,7 @@ impl GossipUi {
|
||||
|
||||
GossipUi {
|
||||
next_frame: Instant::now(),
|
||||
page: Page::FeedGeneral,
|
||||
page: Page::Feed(FeedKind::General),
|
||||
about: crate::about::about(),
|
||||
icon: icon_texture_handle,
|
||||
placeholder_avatar: placeholder_avatar_texture_handle,
|
||||
@ -162,7 +159,6 @@ impl GossipUi {
|
||||
import_priv: "".to_owned(),
|
||||
import_pub: "".to_owned(),
|
||||
replying_to: None,
|
||||
person_view_pubkey: None,
|
||||
avatars: HashMap::new(),
|
||||
new_relay_url: "".to_owned(),
|
||||
tag_re: regex::Regex::new(r"(\#\[\d+\])").unwrap(),
|
||||
@ -192,15 +188,12 @@ impl eframe::App for GossipUi {
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add(SelectableLabel::new(
|
||||
self.page == Page::FeedGeneral
|
||||
|| self.page == Page::FeedReplies
|
||||
|| self.page == Page::FeedThread
|
||||
|| self.page == Page::FeedPerson,
|
||||
matches!(self.page, Page::Feed(_)),
|
||||
"Feed",
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
self.page = Page::FeedGeneral;
|
||||
self.page = Page::Feed(FeedKind::General);
|
||||
GLOBALS.events.clear_new();
|
||||
}
|
||||
ui.separator();
|
||||
@ -208,7 +201,7 @@ impl eframe::App for GossipUi {
|
||||
.add(SelectableLabel::new(
|
||||
self.page == Page::PeopleList
|
||||
|| self.page == Page::PeopleFollow
|
||||
|| self.page == Page::Person,
|
||||
|| matches!(self.page, Page::Person(_)),
|
||||
"People",
|
||||
))
|
||||
.clicked()
|
||||
@ -270,10 +263,8 @@ impl eframe::App for GossipUi {
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| match self.page {
|
||||
Page::FeedGeneral | Page::FeedReplies | Page::FeedThread | Page::FeedPerson => {
|
||||
feed::update(self, ctx, frame, ui)
|
||||
}
|
||||
Page::PeopleList | Page::PeopleFollow | Page::Person => {
|
||||
Page::Feed(_) => feed::update(self, ctx, frame, ui),
|
||||
Page::PeopleList | Page::PeopleFollow | Page::Person(_) => {
|
||||
people::update(self, ctx, frame, ui)
|
||||
}
|
||||
Page::You => you::update(self, ctx, frame, ui),
|
||||
|
@ -9,10 +9,9 @@ mod follow;
|
||||
mod person;
|
||||
|
||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let maybe_person = if let Some(pubkeyhex) = &app.person_view_pubkey {
|
||||
GLOBALS.people.get(pubkeyhex)
|
||||
} else {
|
||||
None
|
||||
let maybe_person = match &app.page {
|
||||
Page::Person(pubkeyhex) => GLOBALS.people.get(pubkeyhex),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
@ -21,7 +20,11 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
||||
ui.selectable_value(&mut app.page, Page::PeopleFollow, "Follow Someone New");
|
||||
ui.separator();
|
||||
if let Some(person) = &maybe_person {
|
||||
ui.selectable_value(&mut app.page, Page::Person, get_name(person));
|
||||
ui.selectable_value(
|
||||
&mut app.page,
|
||||
Page::Person(person.pubkey.clone()),
|
||||
get_name(person),
|
||||
);
|
||||
ui.separator();
|
||||
}
|
||||
});
|
||||
@ -97,7 +100,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
||||
});
|
||||
} else if app.page == Page::PeopleFollow {
|
||||
follow::update(app, ctx, _frame, ui);
|
||||
} else if app.page == Page::Person {
|
||||
} else if matches!(app.page, Page::Person(_)) {
|
||||
person::update(app, ctx, _frame, ui);
|
||||
}
|
||||
}
|
||||
@ -111,6 +114,5 @@ fn get_name(person: &DbPerson) -> String {
|
||||
}
|
||||
|
||||
fn set_person_view(app: &mut GossipUi, person: &DbPerson) {
|
||||
app.person_view_pubkey = Some(person.pubkey.clone());
|
||||
app.page = Page::Person;
|
||||
app.page = Page::Person(person.pubkey.clone());
|
||||
}
|
||||
|
@ -1,71 +1,72 @@
|
||||
use super::{GossipUi, Page};
|
||||
use crate::comms::ToOverlordMessage;
|
||||
use crate::db::DbPerson;
|
||||
use crate::feed::FeedKind;
|
||||
use crate::globals::GLOBALS;
|
||||
use eframe::egui;
|
||||
use egui::{Context, RichText, Ui, Vec2};
|
||||
|
||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
let maybe_person = if let Some(pubkeyhex) = &app.person_view_pubkey {
|
||||
GLOBALS.people.get(pubkeyhex)
|
||||
} else {
|
||||
None
|
||||
let (pubkeyhex, maybe_person) = match &app.page {
|
||||
Page::Person(pubkeyhex) => {
|
||||
let maybe_person = GLOBALS.people.get(pubkeyhex);
|
||||
(pubkeyhex.to_owned(), maybe_person)
|
||||
}
|
||||
_ => {
|
||||
ui.label("ERROR");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if maybe_person.is_none() || app.person_view_pubkey.is_none() {
|
||||
ui.label("ERROR");
|
||||
} else {
|
||||
let person = maybe_person.as_ref().unwrap();
|
||||
let pubkeyhex = app.person_view_pubkey.as_ref().unwrap().clone();
|
||||
let person = maybe_person.as_ref().unwrap();
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.add_space(24.0);
|
||||
|
||||
ui.heading(get_name(person));
|
||||
ui.heading(get_name(person));
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
// Avatar first
|
||||
let avatar = if let Some(avatar) = app.try_get_avatar(ctx, &pubkeyhex) {
|
||||
avatar
|
||||
} else {
|
||||
app.placeholder_avatar.clone()
|
||||
};
|
||||
ui.image(&avatar, Vec2 { x: 36.0, y: 36.0 });
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(GossipUi::hex_pubkey_short(&pubkeyhex)).weak());
|
||||
GossipUi::render_person_name_line(ui, Some(person));
|
||||
});
|
||||
});
|
||||
|
||||
ui.add_space(12.0);
|
||||
|
||||
if let Some(about) = person.about.as_deref() {
|
||||
ui.label(about);
|
||||
}
|
||||
|
||||
ui.add_space(12.0);
|
||||
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if person.followed == 0 {
|
||||
if ui.button("FOLLOW").clicked() {
|
||||
GLOBALS.people.follow(&pubkeyhex, true);
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
// Avatar first
|
||||
let avatar = if let Some(avatar) = app.try_get_avatar(ctx, &pubkeyhex) {
|
||||
avatar
|
||||
} else {
|
||||
if ui.button("UNFOLLOW").clicked() {
|
||||
GLOBALS.people.follow(&pubkeyhex, false);
|
||||
}
|
||||
}
|
||||
app.placeholder_avatar.clone()
|
||||
};
|
||||
ui.image(&avatar, Vec2 { x: 36.0, y: 36.0 });
|
||||
|
||||
if ui.button("UPDATE METADATA").clicked() {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::UpdateMetadata(pubkeyhex.clone()));
|
||||
}
|
||||
ui.vertical(|ui| {
|
||||
ui.label(RichText::new(GossipUi::hex_pubkey_short(&pubkeyhex)).weak());
|
||||
GossipUi::render_person_name_line(ui, Some(person));
|
||||
});
|
||||
});
|
||||
|
||||
if ui.button("VIEW THEIR FEED").clicked() {
|
||||
GLOBALS.feed.set_feed_to_person(pubkeyhex.clone());
|
||||
app.page = Page::FeedPerson;
|
||||
ui.add_space(12.0);
|
||||
|
||||
if let Some(about) = person.about.as_deref() {
|
||||
ui.label(about);
|
||||
}
|
||||
|
||||
ui.add_space(12.0);
|
||||
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if person.followed == 0 {
|
||||
if ui.button("FOLLOW").clicked() {
|
||||
GLOBALS.people.follow(&pubkeyhex, true);
|
||||
}
|
||||
} else {
|
||||
if ui.button("UNFOLLOW").clicked() {
|
||||
GLOBALS.people.follow(&pubkeyhex, false);
|
||||
}
|
||||
}
|
||||
|
||||
if ui.button("UPDATE METADATA").clicked() {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::UpdateMetadata(pubkeyhex.clone()));
|
||||
}
|
||||
|
||||
if ui.button("VIEW THEIR FEED").clicked() {
|
||||
GLOBALS.feed.set_feed_to_person(pubkeyhex.clone());
|
||||
app.page = Page::Feed(FeedKind::Person(pubkeyhex.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user