- Overhaul UI style
- reduce number of buttons
This commit is contained in:
Bu5hm4nn 2024-03-05 20:59:04 -06:00
parent 065c967fea
commit 214a93287b
10 changed files with 406 additions and 222 deletions

View File

@ -250,39 +250,25 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label(" • Profile (nprofile1..)");
ui.label(" • DNS ID (user@domain)");
if app.wizard_state.has_private_key {
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
ui.checkbox(
&mut app.wizard_state.follow_list_should_publish,
"Publish Following List",
);
});
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
if app.wizard_state.has_private_key {
ui.scope(|ui| {
if app.wizard_state.new_user {
app.theme.accent_button_1_style(ui.style_mut());
} else {
app.theme.accent_button_2_style(ui.style_mut());
}
if ui.button("Publish and Finish").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::PushPersonList(PersonList::Followed));
super::complete_wizard(app, ctx);
}
});
ui.add_space(20.0);
ui.scope(|ui| {
if !app.wizard_state.new_user {
app.theme.accent_button_1_style(ui.style_mut());
} else {
app.theme.accent_button_2_style(ui.style_mut());
}
if ui.button("Finish without publishing").clicked() {
super::complete_wizard(app, ctx);
}
});
} else {
app.theme.accent_button_1_style(ui.style_mut());
if ui.button("Finish").clicked() {
super::complete_wizard(app, ctx);
app.theme.accent_button_1_style(ui.style_mut());
if ui.button("Finish").clicked() {
if app.wizard_state.follow_list_should_publish {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::PushPersonList(PersonList::Followed));
}
super::complete_wizard(app, ctx);
}
});
}

View File

@ -1,7 +1,11 @@
use crate::ui::widgets::list_entry::{self};
use crate::ui::wizard::WizardPage;
use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::{Context, RichText, Ui};
use egui::{Context, Ui};
use super::wizard_controls;
use super::wizard_state::WizardPath;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
if app.wizard_state.pubkey.is_some() {
@ -9,24 +13,76 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
return;
};
ui.add_space(20.0);
let selected = app.wizard_state.path == WizardPath::ImportFromKey(true);
let response = list_entry::make_frame(ui, None)
.stroke(if selected {
egui::Stroke::new(1.0, app.theme.accent_color())
} else {
egui::Stroke::new(1.0, egui::Color32::TRANSPARENT)
})
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
ui.add(egui::RadioButton::new(selected, ""));
ui.add_space(10.0);
ui.label("Import a Private Key")
.on_hover_cursor(egui::CursorIcon::Default);
})
});
if ui
.button(RichText::new(" > Import a Private Key").color(app.theme.accent_color()))
.interact(
response.response.rect,
ui.next_auto_id(),
egui::Sense::click(),
)
.clicked()
{
app.set_page(ctx, Page::Wizard(WizardPage::ImportPrivateKey));
app.wizard_state.path = WizardPath::ImportFromKey(true);
}
let selected = app.wizard_state.path == WizardPath::ImportFromKey(false);
let response = list_entry::make_frame(ui, None)
.stroke(if selected {
egui::Stroke::new(1.0, app.theme.accent_color())
} else {
egui::Stroke::new(1.0, egui::Color32::TRANSPARENT)
})
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
ui.add(egui::RadioButton::new(selected, ""));
ui.add_space(10.0);
ui.label("Import a Public Key")
.on_hover_cursor(egui::CursorIcon::Default);
})
});
if ui
.interact(
response.response.rect,
ui.next_auto_id(),
egui::Sense::click(),
)
.clicked()
{
app.wizard_state.path = WizardPath::ImportFromKey(false);
}
ui.add_space(20.0);
if ui
.button(RichText::new(" > Import a Public Key only").color(app.theme.accent_color()))
.clicked()
{
app.set_page(ctx, Page::Wizard(WizardPage::ImportPublicKey));
}
ui.add_space(20.0);
if ui.button(" < Go Back").clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::WelcomeGossip));
}
wizard_controls(
ui,
app,
true,
|app| {
app.set_page(ctx, Page::Wizard(WizardPage::WelcomeGossip));
},
|app| match app.wizard_state.path {
super::wizard_state::WizardPath::ImportFromKey(true) => {
app.set_page(ctx, Page::Wizard(WizardPage::ImportPrivateKey));
}
super::wizard_state::WizardPath::ImportFromKey(false) => {
app.set_page(ctx, Page::Wizard(WizardPage::ImportPublicKey));
}
_ => {}
},
);
}

View File

@ -6,6 +6,8 @@ use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::GLOBALS;
use zeroize::Zeroize;
use super::wizard_controls;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
// If already imported, advance
if app.wizard_state.has_private_key {
@ -86,22 +88,22 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
let ready = !app.import_priv.is_empty() && !password_mismatch;
if ready {
if app.password.is_empty() {
ui.add_space(10.0);
if ready && app.password.is_empty() {
ui.add_space(10.0);
ui.label(
RichText::new("Your password is empty!")
.color(app.theme.warning_marker_text_color()),
);
}
ui.label(
RichText::new("Your password is empty!").color(app.theme.warning_marker_text_color()),
);
}
ui.add_space(20.0);
if ui
.button(RichText::new(" > Import").color(app.theme.accent_color()))
.clicked()
{
wizard_controls(
ui,
app,
ready,
|app| {
app.set_page(ctx, Page::Wizard(WizardPage::ImportKeys));
},
|app| {
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::ImportPriv {
privkey: app.import_priv.clone(),
password: app.password.clone(),
@ -112,11 +114,6 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
app.password = "".to_owned();
app.password2.zeroize();
app.password2 = "".to_owned();
}
}
ui.add_space(20.0);
if ui.button(" < Go Back").clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::ImportKeys));
}
},
)
}

View File

@ -4,6 +4,9 @@ use eframe::egui;
use egui::{Context, RichText, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::GLOBALS;
use nostr_types::{Profile, PublicKey};
use super::wizard_controls;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
// If already imported, advance
@ -21,39 +24,45 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.horizontal_wrapped(|ui| {
ui.label("Enter your public key");
let response = text_edit_line!(app, app.import_pub)
text_edit_line!(app, app.import_pub)
.with_paste()
.desired_width(f32::INFINITY)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
.show(ui);
});
let ready = try_parse_pubkey(&app.import_pub).is_ok();
// error block
if let Some(err) = &app.wizard_state.error {
ui.add_space(10.0);
ui.label(RichText::new(err).color(app.theme.warning_marker_text_color()));
}
let ready = !app.import_pub.is_empty();
if ready {
ui.add_space(10.0);
if ui
.button(RichText::new(" > Import").color(app.theme.accent_color()))
.clicked()
{
ui.add_space(20.0); // vertical space
wizard_controls(
ui,
app,
ready,
|app| {
app.set_page(ctx, Page::Wizard(WizardPage::ImportKeys));
},
|app| {
app.wizard_state.error = None;
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::ImportPub(app.import_pub.clone()));
app.import_pub = "".to_owned();
}
}
},
);
}
ui.add_space(20.0);
if ui.button(" < Go Back").clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::ImportKeys));
fn try_parse_pubkey(keystr: &str) -> Result<(), ()> {
if PublicKey::try_from_bech32_string(keystr.trim(), true).is_ok()
|| PublicKey::try_from_hex_string(keystr.trim(), true).is_ok()
|| Profile::try_from_bech32_string(keystr.trim(), true).is_ok()
{
Ok(())
} else {
Err(())
}
}

View File

@ -2,6 +2,7 @@ use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::widgets::{Button, Slider};
use egui::{Align, Context, Layout};
use egui_winit::egui::{vec2, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::{FeedKind, PersonList, Relay, GLOBALS};
use nostr_types::RelayUrl;
@ -19,6 +20,10 @@ mod welcome_nostr;
mod wizard_state;
pub use wizard_state::WizardState;
use super::widgets::list_entry::OUTER_MARGIN_RIGHT;
const CONTINUE_BTN_TEXT: &str = "Continue \u{25b6}";
const BACK_BTN_TEXT: &str = "\u{25c0} Go Back";
static DEFAULT_RELAYS: [&str; 20] = [
"wss://nostr.einundzwanzig.space/",
"wss://nostr.mutinywallet.com/",
@ -299,3 +304,49 @@ where
.to_overlord
.send(ToOverlordMessage::UpdateRelay(old, relay));
}
fn continue_button() -> impl egui::Widget {
egui::Button::new(CONTINUE_BTN_TEXT).min_size(vec2(80.0, 0.0))
}
fn back_button() -> impl egui::Widget {
egui::Button::new(BACK_BTN_TEXT).min_size(vec2(80.0, 0.0))
}
fn continue_control(
ui: &mut Ui,
app: &mut GossipUi,
can_continue: bool,
on_continue: impl FnOnce(&mut GossipUi),
) {
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
ui.add_space(OUTER_MARGIN_RIGHT);
app.theme.accent_button_1_style(ui.style_mut());
if ui.add_enabled(can_continue, continue_button()).clicked() {
on_continue(app);
}
});
}
fn wizard_controls(
ui: &mut Ui,
app: &mut GossipUi,
can_continue: bool,
on_back: impl FnOnce(&mut GossipUi),
on_continue: impl FnOnce(&mut GossipUi),
) {
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
ui.add_space(OUTER_MARGIN_RIGHT);
ui.scope(|ui| {
app.theme.accent_button_1_style(ui.style_mut());
if ui.add_enabled(can_continue, continue_button()).clicked() {
on_continue(app);
}
});
ui.add_space(10.0);
ui.style_mut().spacing.button_padding.x *= 3.0;
if ui.add(back_button()).clicked() {
on_back(app);
}
});
}

View File

@ -8,6 +8,8 @@ use gossip_lib::GLOBALS;
use gossip_relay_picker::Direction;
use nostr_types::RelayUrl;
use super::continue_control;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
// New users dont have existing config
if app.wizard_state.new_user {
@ -130,28 +132,26 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
if ready {
ui.add_space(20.0);
if ui.button(" > Fetch From This Relay").clicked() {
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::SubscribeConfig(Some(vec![
rurl.to_owned()
])));
app.wizard_state.relay_url = String::new();
} else {
app.wizard_state.error = Some("ERROR: Invalid Relay URL".to_owned());
ui.scope(|ui| {
app.theme.accent_button_2_style(ui.style_mut());
if ui.button("Fetch From This Relay").clicked() {
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::SubscribeConfig(Some(vec![
rurl.to_owned()
])));
app.wizard_state.relay_url = String::new();
} else {
app.wizard_state.error = Some("ERROR: Invalid Relay URL".to_owned());
}
}
}
});
}
}
ui.add_space(20.0);
let label = if app.wizard_state.need_relay_list() || app.wizard_state.need_user_data() {
" > Skip this step"
} else {
" > Next"
};
if ui.button(label).clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::SetupRelays))
}
continue_control(ui, app, true, |app| {
app.set_page(ctx, Page::Wizard(WizardPage::SetupRelays));
});
}

View File

@ -1,3 +1,4 @@
use crate::ui::widgets::list_entry::OUTER_MARGIN_RIGHT;
use crate::ui::wizard::WizardPage;
use crate::ui::{GossipUi, Page, RichText};
use eframe::egui;
@ -7,6 +8,9 @@ use gossip_lib::Person;
use gossip_lib::GLOBALS;
use nostr_types::Metadata;
use super::continue_control;
use super::wizard_state::WizardPath;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
let pubkey = match app.wizard_state.pubkey {
Some(pk) => pk,
@ -51,40 +55,63 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
app.wizard_state.metadata_copied = true;
}
ui.horizontal(|ui| {
ui.label("Name:");
let response = text_edit_line!(app, app.wizard_state.metadata_name)
.with_paste()
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
});
egui::Grid::new("grid")
.num_columns(2)
.striped(false)
.spacing([10.0, 10.0])
.show(ui, |ui| {
ui.label("Name:");
let response = text_edit_line!(app, app.wizard_state.metadata_name)
.desired_width(400.0)
.with_paste()
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
ui.end_row();
ui.add_space(15.0);
ui.horizontal(|ui| {
ui.label("About:");
let response = text_edit_line!(app, app.wizard_state.metadata_about)
.with_paste()
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
});
ui.label("About:");
let response = text_edit_line!(app, app.wizard_state.metadata_about)
.desired_width(400.0)
.with_paste()
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
ui.add_space(15.0);
ui.horizontal(|ui| {
ui.label("Picture:");
let response = text_edit_line!(app, app.wizard_state.metadata_picture)
.with_paste()
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
});
ui.end_row();
ui.label("Picture URL:");
let response = text_edit_line!(app, app.wizard_state.metadata_picture)
.desired_width(400.0)
.with_paste()
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
}
ui.end_row();
ui.label(""); // fill first cell
if WizardPath::ImportFromKey(true) == app.wizard_state.path {
if ui.button("Undo Changes").clicked() {
if let Some(n) = &metadata.name {
app.wizard_state.metadata_name = n.to_owned();
}
if let Some(n) = &metadata.about {
app.wizard_state.metadata_about = n.to_owned();
}
if let Some(n) = &metadata.picture {
app.wizard_state.metadata_picture = n.to_owned();
}
}
}
ui.end_row();
});
// error block
if let Some(err) = &app.wizard_state.error {
@ -92,46 +119,31 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label(RichText::new(err).color(app.theme.warning_marker_text_color()));
}
ui.add_space(15.0);
ui.add_space(20.0);
if GLOBALS.identity.is_unlocked() {
ui.add_space(20.0);
let mut label = RichText::new(" > Save, Publish and Continue");
if app.wizard_state.new_user {
label = label.color(app.theme.accent_color());
}
if ui.button(label).clicked() {
// Copy from form and save
save_metadata(app, you.clone(), metadata.clone());
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
ui.add_space(OUTER_MARGIN_RIGHT);
ui.checkbox(
&mut app.wizard_state.metadata_should_publish,
"Publish this Profile",
);
});
ui.add_space(10.0);
}
continue_control(ui, app, true, |app| {
// Copy from form and save
save_metadata(app, you.clone(), metadata.clone());
if app.wizard_state.metadata_should_publish {
// Publish
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::PushMetadata(metadata.clone()));
app.set_page(ctx, Page::Wizard(WizardPage::FollowPeople));
}
}
ui.add_space(20.0);
if ui
.button(" > Save and Continue without publishing")
.clicked()
{
// Copy from form and save
save_metadata(app, you.clone(), metadata.clone());
app.set_page(ctx, Page::Wizard(WizardPage::FollowPeople));
}
ui.add_space(20.0);
let mut label = RichText::new(" > Continue without saving or publishing");
if !app.wizard_state.new_user {
label = label.color(app.theme.accent_color());
}
if ui.button(label).clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::FollowPeople));
}
});
}
fn save_metadata(app: &mut GossipUi, mut you: Person, mut metadata: Metadata) {

View File

@ -1,11 +1,13 @@
use super::modify_relay;
use super::{continue_control, modify_relay};
use crate::ui::widgets::list_entry::OUTER_MARGIN_RIGHT;
use crate::ui::wizard::{WizardPage, DEFAULT_RELAYS};
use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::{Button, Color32, Context, RichText, Ui};
use egui_winit::egui::vec2;
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::Relay;
use gossip_lib::GLOBALS;
use gossip_lib::{PersonList, Relay};
use nostr_types::RelayUrl;
use std::collections::BTreeMap;
@ -228,37 +230,42 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
});
}
ui.add_space(20.0);
ui.separator();
ui.add_space(20.0);
if app.wizard_state.has_private_key {
ui.add_space(20.0);
let mut label = RichText::new(" > Publish and Continue");
if app.wizard_state.new_user {
label = label.color(app.theme.accent_color());
}
if ui.button(label).clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::AdvertiseRelayList);
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
ui.add_space(OUTER_MARGIN_RIGHT);
ui.checkbox(
&mut app.wizard_state.relays_should_publish,
"Publish this Relay list",
);
});
ui.add_space(10.0);
continue_control(ui, app, true, |app| {
if app.wizard_state.relays_should_publish {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::AdvertiseRelayList);
}
app.set_page(ctx, Page::Wizard(WizardPage::SetupMetadata));
}
ui.add_space(20.0);
let mut label = RichText::new(" > Continue without publishing");
if !app.wizard_state.new_user {
label = label.color(app.theme.accent_color());
}
if ui.button(label).clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::SetupMetadata));
};
});
} else {
ui.add_space(20.0);
let mut label = RichText::new(" > Continue");
label = label.color(app.theme.accent_color());
if ui.button(label).clicked() {
app.set_page(ctx, Page::Wizard(WizardPage::FollowPeople));
};
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
ui.add_space(OUTER_MARGIN_RIGHT);
app.theme.accent_button_1_style(ui.style_mut());
if ui
.add(egui::Button::new("Finish").min_size(vec2(80.0, 0.0)))
.clicked()
{
// import existing lists and start the app
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UpdatePersonList {
person_list: PersonList::Followed,
merge: false,
});
super::complete_wizard(app, ctx);
}
});
}
}

View File

@ -1,9 +1,13 @@
use crate::ui::widgets::list_entry::{self, OUTER_MARGIN_RIGHT};
use crate::ui::wizard::WizardPage;
use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::{Context, RichText, Ui};
use egui::{Context, Ui};
use gossip_lib::GLOBALS;
use super::continue_button;
use super::wizard_state::WizardPath;
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
if app.wizard_state.pubkey.is_some() {
app.set_page(ctx, Page::Wizard(WizardPage::ReadNostrConfig));
@ -17,35 +21,77 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label("Please select from the following choices:");
ui.add_space(20.0);
if ui
.button(RichText::new(" > Create a New Nostr Account").color(app.theme.accent_color()))
.clicked()
{
app.wizard_state.new_user = true;
app.set_page(ctx, Page::Wizard(WizardPage::WelcomeNostr));
}
ui.add_space(20.0);
render_wizard_path_choice(ui, app, WizardPath::CreateNewAccount);
render_wizard_path_choice(ui, app, WizardPath::ImportFromKey(true));
render_wizard_path_choice(ui, app, WizardPath::FollowOnlyNoKeys);
ui.add_space(20.0); // vertical space
ui.horizontal(|ui| {
if ui.button("Exit Setup Wizard").clicked() {
super::complete_wizard(app, ctx);
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::default()), |ui| {
app.theme.accent_button_1_style(ui.style_mut());
ui.add_space(OUTER_MARGIN_RIGHT);
if ui.add(continue_button()).clicked() {
match app.wizard_state.path {
WizardPath::CreateNewAccount => {
app.wizard_state.new_user = true;
app.set_page(ctx, Page::Wizard(WizardPage::WelcomeNostr));
}
WizardPath::ImportFromKey(_) => {
app.wizard_state.new_user = false;
app.set_page(ctx, Page::Wizard(WizardPage::ImportKeys))
}
WizardPath::FollowOnlyNoKeys => {
app.wizard_state.new_user = false;
app.wizard_state.follow_only = true;
let _ = GLOBALS.storage.set_flag_following_only(true, None);
app.set_page(ctx, Page::Wizard(WizardPage::FollowPeople));
}
}
}
});
});
}
fn wizard_path_name(path: WizardPath) -> &'static str {
match path {
WizardPath::CreateNewAccount => "Create a New Nostr Account",
WizardPath::ImportFromKey(_) => "I Already have a Nostr Account",
WizardPath::FollowOnlyNoKeys => "Just follow people (no account)",
}
}
fn render_wizard_path_choice(ui: &mut Ui, app: &mut GossipUi, choice: WizardPath) {
let selected = app.wizard_state.path == choice;
let response = list_entry::make_frame(ui, None)
.stroke(if selected {
egui::Stroke::new(1.0, app.theme.accent_color())
} else {
egui::Stroke::new(1.0, egui::Color32::TRANSPARENT)
})
.show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
ui.add(egui::RadioButton::new(selected, ""));
ui.add_space(10.0);
ui.label(wizard_path_name(choice))
.on_hover_cursor(egui::CursorIcon::Default);
})
});
if ui
.button(
RichText::new(" > I Already have a Nostr Account").color(app.theme.accent_color()),
.interact(
response.response.rect,
ui.next_auto_id(),
egui::Sense::click(),
)
.clicked()
{
app.wizard_state.new_user = false;
app.set_page(ctx, Page::Wizard(WizardPage::ImportKeys))
}
ui.add_space(20.0);
if ui.button(" > Just follow people (no account)").clicked() {
app.wizard_state.new_user = false;
app.wizard_state.follow_only = true;
let _ = GLOBALS.storage.set_flag_following_only(true, None);
app.set_page(ctx, Page::Wizard(WizardPage::FollowPeople));
}
ui.add_space(20.0);
if ui.button(" X Exit this Wizard").clicked() {
super::complete_wizard(app, ctx);
app.wizard_state.path = choice;
}
}

View File

@ -2,8 +2,21 @@ use gossip_lib::{Person, PersonList, Relay, GLOBALS};
use nostr_types::{Event, EventKind, PublicKey, RelayUrl};
use std::{cell::RefCell, collections::HashSet, rc::Rc};
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum WizardPath {
/// the user wants to import an existing account from
/// a private (true) or public key (false)
ImportFromKey(bool),
/// the user wants to create a new account
CreateNewAccount,
/// the user only wants to create a local follow list
/// without setting up any keys
FollowOnlyNoKeys,
}
#[derive(Debug)]
pub struct WizardState {
pub path: WizardPath,
pub error: Option<String>,
pub last_status_queue_message: String,
pub new_user: bool,
@ -14,15 +27,18 @@ pub struct WizardState {
pub metadata_name: String,
pub metadata_about: String,
pub metadata_picture: String,
pub metadata_should_publish: bool,
pub pubkey: Option<PublicKey>,
pub has_private_key: bool,
pub metadata_events: Vec<Event>,
pub contact_list_events: Vec<Event>,
pub relay_list_events: Vec<Event>,
pub relays: Vec<Relay>,
pub relays_should_publish: bool,
pub followed: Vec<(Option<PublicKey>, Option<Rc<RefCell<Person>>>)>,
pub followed_last_try: f64,
pub followed_getting_metadata: HashSet<PublicKey>,
pub follow_list_should_publish: bool,
pub contacts_sought: bool,
pub generating: bool,
}
@ -30,6 +46,7 @@ pub struct WizardState {
impl Default for WizardState {
fn default() -> WizardState {
WizardState {
path: WizardPath::CreateNewAccount,
error: None,
last_status_queue_message: "".to_owned(),
new_user: false,
@ -40,15 +57,18 @@ impl Default for WizardState {
metadata_name: "".to_owned(),
metadata_about: "".to_owned(),
metadata_picture: "".to_owned(),
metadata_should_publish: true,
pubkey: None,
has_private_key: false,
metadata_events: Vec::new(),
contact_list_events: Vec::new(),
relay_list_events: Vec::new(),
relays: Vec::new(),
relays_should_publish: true,
followed: Vec::new(),
followed_last_try: 0.0,
followed_getting_metadata: HashSet::new(),
follow_list_should_publish: true,
contacts_sought: true,
generating: false,
}