mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Nav
This commit is contained in:
parent
2a5abebff2
commit
ab80931e7f
@ -9,7 +9,7 @@ use egui::{
|
|||||||
Separator, Stroke, TextEdit, TextStyle, Ui, Vec2,
|
Separator, Stroke, TextEdit, TextStyle, Ui, Vec2,
|
||||||
};
|
};
|
||||||
use linkify::{LinkFinder, LinkKind};
|
use linkify::{LinkFinder, LinkKind};
|
||||||
use nostr_types::{Event, EventKind, Id, IdHex, PublicKeyHex, Tag};
|
use nostr_types::{Event, EventKind, Id, IdHex, Tag};
|
||||||
|
|
||||||
struct FeedPostParams {
|
struct FeedPostParams {
|
||||||
id: Id,
|
id: Id,
|
||||||
@ -19,8 +19,7 @@ struct FeedPostParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 mut feed_kind = GLOBALS.feed.get_feed_kind();
|
let feed_kind = GLOBALS.feed.get_feed_kind();
|
||||||
app.page = Page::Feed(feed_kind.clone());
|
|
||||||
|
|
||||||
// Feed Page Selection
|
// Feed Page Selection
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
@ -31,10 +30,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
feed_kind = FeedKind::General;
|
app.set_page(Page::Feed(FeedKind::General));
|
||||||
app.page = Page::Feed(feed_kind.clone());
|
|
||||||
GLOBALS.feed.set_feed_to_general();
|
|
||||||
GLOBALS.events.clear_new();
|
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui
|
if ui
|
||||||
@ -44,10 +40,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
feed_kind = FeedKind::Replies;
|
app.set_page(Page::Feed(FeedKind::Replies));
|
||||||
app.page = Page::Feed(feed_kind.clone());
|
|
||||||
GLOBALS.feed.set_feed_to_replies();
|
|
||||||
GLOBALS.events.clear_new();
|
|
||||||
}
|
}
|
||||||
if matches!(feed_kind.clone(), FeedKind::Thread(..)) {
|
if matches!(feed_kind.clone(), FeedKind::Thread(..)) {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
@ -76,7 +69,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("You need to ");
|
ui.label("You need to ");
|
||||||
if ui.link("setup an identity").clicked() {
|
if ui.link("setup an identity").clicked() {
|
||||||
app.page = Page::Relays;
|
app.set_page(Page::Relays);
|
||||||
}
|
}
|
||||||
ui.label(" to see any replies to that identity.");
|
ui.label(" to see any replies to that identity.");
|
||||||
});
|
});
|
||||||
@ -103,7 +96,7 @@ fn posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("You need to ");
|
ui.label("You need to ");
|
||||||
if ui.link("setup your identity").clicked() {
|
if ui.link("setup your identity").clicked() {
|
||||||
app.page = Page::You;
|
app.set_page(Page::You);
|
||||||
}
|
}
|
||||||
ui.label(" to post.");
|
ui.label(" to post.");
|
||||||
});
|
});
|
||||||
@ -111,7 +104,7 @@ fn posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("You need to ");
|
ui.label("You need to ");
|
||||||
if ui.link("choose relays").clicked() {
|
if ui.link("choose relays").clicked() {
|
||||||
app.page = Page::Relays;
|
app.set_page(Page::Relays);
|
||||||
}
|
}
|
||||||
ui.label(" to post.");
|
ui.label(" to post.");
|
||||||
});
|
});
|
||||||
@ -460,7 +453,7 @@ fn render_post_actual(
|
|||||||
)
|
)
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
set_person_view(app, &event.pubkey.into());
|
app.set_page(Page::Person(event.pubkey.into()));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Everything else next
|
// Everything else next
|
||||||
@ -481,8 +474,7 @@ fn render_post_actual(
|
|||||||
// the parent might not exist and that would leave us
|
// the parent might not exist and that would leave us
|
||||||
// stranded, but we KNOW the child exists, and it's
|
// stranded, but we KNOW the child exists, and it's
|
||||||
// ancestors will render when they become available.
|
// ancestors will render when they become available.
|
||||||
GLOBALS.feed.set_feed_to_thread(event.id);
|
app.set_page(Page::Feed(FeedKind::Thread(event.id)));
|
||||||
app.page = Page::Feed(FeedKind::Thread(event.id));
|
|
||||||
};
|
};
|
||||||
ui.reset_style();
|
ui.reset_style();
|
||||||
}
|
}
|
||||||
@ -496,8 +488,7 @@ fn render_post_actual(
|
|||||||
ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
|
ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
|
||||||
ui.menu_button(RichText::new("≡").size(28.0), |ui| {
|
ui.menu_button(RichText::new("≡").size(28.0), |ui| {
|
||||||
if !is_main_event && ui.button("View Thread").clicked() {
|
if !is_main_event && ui.button("View Thread").clicked() {
|
||||||
GLOBALS.feed.set_feed_to_thread(event.id);
|
app.set_page(Page::Feed(FeedKind::Thread(event.id)));
|
||||||
app.page = Page::Feed(FeedKind::Thread(event.id));
|
|
||||||
}
|
}
|
||||||
if ui.button("Copy ID").clicked() {
|
if ui.button("Copy ID").clicked() {
|
||||||
ui.output().copied_text = event.id.as_hex_string();
|
ui.output().copied_text = event.id.as_hex_string();
|
||||||
@ -514,8 +505,7 @@ fn render_post_actual(
|
|||||||
|
|
||||||
if !is_main_event && ui.button("➤").on_hover_text("View Thread").clicked()
|
if !is_main_event && ui.button("➤").on_hover_text("View Thread").clicked()
|
||||||
{
|
{
|
||||||
GLOBALS.feed.set_feed_to_thread(event.id);
|
app.set_page(Page::Feed(FeedKind::Thread(event.id)));
|
||||||
app.page = Page::Feed(FeedKind::Thread(event.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.label(
|
ui.label(
|
||||||
@ -629,15 +619,14 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: ®ex::Regex, event:
|
|||||||
None => format!("@{}", GossipUi::hex_pubkey_short(pubkey)),
|
None => format!("@{}", GossipUi::hex_pubkey_short(pubkey)),
|
||||||
};
|
};
|
||||||
if ui.link(&nam).clicked() {
|
if ui.link(&nam).clicked() {
|
||||||
set_person_view(app, pubkey);
|
app.set_page(Page::Person(pubkey.to_owned()));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Tag::Event { id, .. } => {
|
Tag::Event { id, .. } => {
|
||||||
let idhex: IdHex = (*id).into();
|
let idhex: IdHex = (*id).into();
|
||||||
let nam = format!("#{}", GossipUi::hex_id_short(&idhex));
|
let nam = format!("#{}", GossipUi::hex_id_short(&idhex));
|
||||||
if ui.link(&nam).clicked() {
|
if ui.link(&nam).clicked() {
|
||||||
GLOBALS.feed.set_feed_to_thread(*id);
|
app.set_page(Page::Feed(FeedKind::Thread(*id)));
|
||||||
app.page = Page::Feed(FeedKind::Thread(*id));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Tag::Hashtag(s) => {
|
Tag::Hashtag(s) => {
|
||||||
@ -661,10 +650,6 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: ®ex::Regex, event:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_person_view(app: &mut GossipUi, pubkeyhex: &PublicKeyHex) {
|
|
||||||
app.page = Page::Person(pubkeyhex.to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn thin_red_separator(ui: &mut Ui) {
|
fn thin_red_separator(ui: &mut Ui) {
|
||||||
let mut style = ui.style_mut();
|
let mut style = ui.style_mut();
|
||||||
style.visuals.widgets.noninteractive.bg_stroke = Stroke {
|
style.visuals.widgets.noninteractive.bg_stroke = Stroke {
|
||||||
|
@ -54,7 +54,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.label("To get started, go to the");
|
ui.label("To get started, go to the");
|
||||||
if ui.link("People > Follow Someone New").clicked() {
|
if ui.link("People > Follow Someone New").clicked() {
|
||||||
app.page = Page::PeopleFollow;
|
app.set_page(Page::PeopleFollow);
|
||||||
}
|
}
|
||||||
ui.label("page and add people to follow. If you don't know anybody, you can follow me at NIP-05 DNS ID mike@mikedilger.com and you can find other people through me (posts I reply to or quote).");
|
ui.label("page and add people to follow. If you don't know anybody, you can follow me at NIP-05 DNS ID mike@mikedilger.com and you can find other people through me (posts I reply to or quote).");
|
||||||
});
|
});
|
||||||
@ -90,7 +90,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.label("On the");
|
ui.label("On the");
|
||||||
if ui.link("You").clicked() {
|
if ui.link("You").clicked() {
|
||||||
app.page = Page::You;
|
app.set_page(Page::You);
|
||||||
}
|
}
|
||||||
ui.label("page you can setup your identity. If you are new, you should just press \"Generate\" and you are good to go. Otherwise you can import a private key in hex or bech32 format, although it isn't very secure to cut-n-paste and display your private key, so it will mark your key security as \"weak\". Eventually you'll be able to import your password-protected private key from a nostr relay.");
|
ui.label("page you can setup your identity. If you are new, you should just press \"Generate\" and you are good to go. Otherwise you can import a private key in hex or bech32 format, although it isn't very secure to cut-n-paste and display your private key, so it will mark your key security as \"weak\". Eventually you'll be able to import your password-protected private key from a nostr relay.");
|
||||||
});
|
});
|
||||||
@ -115,7 +115,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.label("Go to the");
|
ui.label("Go to the");
|
||||||
if ui.link("Relays").clicked() {
|
if ui.link("Relays").clicked() {
|
||||||
app.page = Page::Relays;
|
app.set_page(Page::Relays);
|
||||||
}
|
}
|
||||||
ui.label("page and tick a half dozen relays that you intend to post to. If your webserver serves a nostr.json file, you can follow NIP-05 and use the same relays in that file.");
|
ui.label("page and tick a half dozen relays that you intend to post to. If your webserver serves a nostr.json file, you can follow NIP-05 and use the same relays in that file.");
|
||||||
});
|
});
|
||||||
|
@ -53,7 +53,7 @@ pub fn run() -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
enum Page {
|
enum Page {
|
||||||
Feed(FeedKind),
|
Feed(FeedKind),
|
||||||
PeopleList,
|
PeopleList,
|
||||||
@ -70,6 +70,7 @@ enum Page {
|
|||||||
struct GossipUi {
|
struct GossipUi {
|
||||||
next_frame: Instant,
|
next_frame: Instant,
|
||||||
page: Page,
|
page: Page,
|
||||||
|
history: Vec<Page>,
|
||||||
about: About,
|
about: About,
|
||||||
icon: TextureHandle,
|
icon: TextureHandle,
|
||||||
placeholder_avatar: TextureHandle,
|
placeholder_avatar: TextureHandle,
|
||||||
@ -143,6 +144,7 @@ impl GossipUi {
|
|||||||
GossipUi {
|
GossipUi {
|
||||||
next_frame: Instant::now(),
|
next_frame: Instant::now(),
|
||||||
page: Page::Feed(FeedKind::General),
|
page: Page::Feed(FeedKind::General),
|
||||||
|
history: vec![],
|
||||||
about: crate::about::about(),
|
about: crate::about::about(),
|
||||||
icon: icon_texture_handle,
|
icon: icon_texture_handle,
|
||||||
placeholder_avatar: placeholder_avatar_texture_handle,
|
placeholder_avatar: placeholder_avatar_texture_handle,
|
||||||
@ -164,6 +166,45 @@ impl GossipUi {
|
|||||||
tag_re: regex::Regex::new(r"(\#\[\d+\])").unwrap(),
|
tag_re: regex::Regex::new(r"(\#\[\d+\])").unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_page(&mut self, page: Page) {
|
||||||
|
if self.page != page {
|
||||||
|
tracing::debug!("PUSHING HISTORY: {:?}", &self.page);
|
||||||
|
self.history.push(self.page.clone());
|
||||||
|
self.set_page_inner(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn back(&mut self) {
|
||||||
|
if let Some(page) = self.history.pop() {
|
||||||
|
tracing::debug!("POPPING HISTORY: {:?}", &page);
|
||||||
|
self.set_page_inner(page);
|
||||||
|
} else {
|
||||||
|
tracing::debug!("HISTORY STUCK ON NONE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_page_inner(&mut self, page: Page) {
|
||||||
|
// Setting the page often requires some associated actions:
|
||||||
|
match &page {
|
||||||
|
Page::Feed(FeedKind::General) => {
|
||||||
|
GLOBALS.feed.set_feed_to_general();
|
||||||
|
GLOBALS.events.clear_new();
|
||||||
|
}
|
||||||
|
Page::Feed(FeedKind::Replies) => {
|
||||||
|
GLOBALS.feed.set_feed_to_replies();
|
||||||
|
GLOBALS.events.clear_new();
|
||||||
|
}
|
||||||
|
Page::Feed(FeedKind::Thread(id)) => {
|
||||||
|
GLOBALS.feed.set_feed_to_thread(*id);
|
||||||
|
}
|
||||||
|
Page::Feed(FeedKind::Person(pubkey)) => {
|
||||||
|
GLOBALS.feed.set_feed_to_person(pubkey.to_owned());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
self.page = page;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for GossipUi {
|
impl eframe::App for GossipUi {
|
||||||
@ -186,6 +227,17 @@ impl eframe::App for GossipUi {
|
|||||||
|
|
||||||
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
|
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
let len = self.history.len();
|
||||||
|
let back_label_text = RichText::new(format!("< Back {}", len));
|
||||||
|
let label = if self.history.is_empty() {
|
||||||
|
Label::new(back_label_text.weak())
|
||||||
|
} else {
|
||||||
|
Label::new(back_label_text).sense(Sense::click())
|
||||||
|
};
|
||||||
|
if ui.add(label).clicked() {
|
||||||
|
self.back();
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
if ui
|
if ui
|
||||||
.add(SelectableLabel::new(
|
.add(SelectableLabel::new(
|
||||||
matches!(self.page, Page::Feed(_)),
|
matches!(self.page, Page::Feed(_)),
|
||||||
@ -193,7 +245,7 @@ impl eframe::App for GossipUi {
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.page = Page::Feed(FeedKind::General);
|
self.set_page(Page::Feed(FeedKind::General));
|
||||||
GLOBALS.events.clear_new();
|
GLOBALS.events.clear_new();
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
@ -206,21 +258,21 @@ impl eframe::App for GossipUi {
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.page = Page::PeopleList;
|
self.set_page(Page::PeopleList);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui
|
if ui
|
||||||
.add(SelectableLabel::new(self.page == Page::You, "You"))
|
.add(SelectableLabel::new(self.page == Page::You, "You"))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.page = Page::You;
|
self.set_page(Page::You);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui
|
if ui
|
||||||
.add(SelectableLabel::new(self.page == Page::Relays, "Relays"))
|
.add(SelectableLabel::new(self.page == Page::Relays, "Relays"))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.page = Page::Relays;
|
self.set_page(Page::Relays);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui
|
if ui
|
||||||
@ -230,7 +282,7 @@ impl eframe::App for GossipUi {
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.page = Page::Settings;
|
self.set_page(Page::Settings);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui
|
if ui
|
||||||
@ -242,7 +294,7 @@ impl eframe::App for GossipUi {
|
|||||||
))
|
))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.page = Page::HelpHelp;
|
self.set_page(Page::HelpHelp);
|
||||||
}
|
}
|
||||||
ui.separator();
|
ui.separator();
|
||||||
});
|
});
|
||||||
|
@ -84,7 +84,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
)
|
)
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
set_person_view(app, person);
|
app.set_page(Page::Person(person.pubkey.clone()));
|
||||||
};
|
};
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
@ -112,7 +112,3 @@ fn get_name(person: &DbPerson) -> String {
|
|||||||
GossipUi::hex_pubkey_short(&person.pubkey)
|
GossipUi::hex_pubkey_short(&person.pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_person_view(app: &mut GossipUi, person: &DbPerson) {
|
|
||||||
app.page = Page::Person(person.pubkey.clone());
|
|
||||||
}
|
|
||||||
|
@ -65,8 +65,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ui.button("VIEW THEIR FEED").clicked() {
|
if ui.button("VIEW THEIR FEED").clicked() {
|
||||||
GLOBALS.feed.set_feed_to_person(pubkeyhex.clone());
|
app.set_page(Page::Feed(FeedKind::Person(pubkeyhex.clone())));
|
||||||
app.page = Page::Feed(FeedKind::Person(pubkeyhex.clone()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user