chore: improve auth handling in startup screen (#160)
* cancel auth * .
This commit is contained in:
@@ -992,7 +992,7 @@ impl ChatSpace {
|
|||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let panel = Arc::new(account::init(secret, profile, window, cx));
|
let panel = Arc::new(account::init(profile, secret, cx));
|
||||||
let center = DockItem::panel(panel);
|
let center = DockItem::panel(panel);
|
||||||
|
|
||||||
self.dock.update(cx, |this, cx| {
|
self.dock.update(cx, |this, cx| {
|
||||||
|
|||||||
@@ -22,18 +22,14 @@ use ui::button::{Button, ButtonVariants};
|
|||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::dock_area::panel::{Panel, PanelEvent};
|
||||||
use ui::indicator::Indicator;
|
use ui::indicator::Indicator;
|
||||||
use ui::input::{InputState, TextInput};
|
use ui::input::{InputState, TextInput};
|
||||||
|
use ui::notification::Notification;
|
||||||
use ui::popup_menu::PopupMenu;
|
use ui::popup_menu::PopupMenu;
|
||||||
use ui::{h_flex, v_flex, ContextModal, Disableable, Sizable, StyledExt};
|
use ui::{h_flex, v_flex, ContextModal, Sizable, StyledExt};
|
||||||
|
|
||||||
use crate::chatspace::ChatSpace;
|
use crate::chatspace::ChatSpace;
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(profile: Profile, secret: String, cx: &mut App) -> Entity<Account> {
|
||||||
secret: String,
|
cx.new(|cx| Account::new(secret, profile, cx))
|
||||||
profile: Profile,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut App,
|
|
||||||
) -> Entity<Account> {
|
|
||||||
Account::new(secret, profile, window, cx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
@@ -49,11 +45,11 @@ pub struct Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
fn new(secret: String, profile: Profile, _window: &mut Window, cx: &mut App) -> Entity<Self> {
|
fn new(secret: String, profile: Profile, cx: &mut App) -> Self {
|
||||||
let is_bunker = secret.starts_with("bunker://");
|
let is_bunker = secret.starts_with("bunker://");
|
||||||
let is_extension = secret.starts_with("extension");
|
let is_extension = secret.starts_with("extension");
|
||||||
|
|
||||||
cx.new(|cx| Self {
|
Self {
|
||||||
profile,
|
profile,
|
||||||
is_bunker,
|
is_bunker,
|
||||||
is_extension,
|
is_extension,
|
||||||
@@ -62,7 +58,7 @@ impl Account {
|
|||||||
name: "Account".into(),
|
name: "Account".into(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
_tasks: smallvec![],
|
_tasks: smallvec![],
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn login(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn login(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -93,8 +89,8 @@ impl Account {
|
|||||||
signer.auth_url_handler(CoopAuthUrlHandler);
|
signer.auth_url_handler(CoopAuthUrlHandler);
|
||||||
|
|
||||||
self._tasks.push(
|
self._tasks.push(
|
||||||
// Handle connection
|
// Handle connection in the background
|
||||||
cx.spawn_in(window, async move |_this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
let client = nostr_client();
|
let client = nostr_client();
|
||||||
|
|
||||||
match signer.bunker_uri().await {
|
match signer.bunker_uri().await {
|
||||||
@@ -103,8 +99,9 @@ impl Account {
|
|||||||
client.set_signer(signer).await;
|
client.set_signer(signer).await;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
window.push_notification(e.to_string(), cx);
|
this.set_loading(false, cx);
|
||||||
|
window.push_notification(Notification::error(e.to_string()), cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -346,41 +343,43 @@ impl Render for Account {
|
|||||||
.text_color(cx.theme().element_foreground)
|
.text_color(cx.theme().element_foreground)
|
||||||
.rounded_lg()
|
.rounded_lg()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.map(|this| {
|
.when(self.loading, |this| {
|
||||||
if self.loading {
|
this.child(
|
||||||
this.child(
|
div()
|
||||||
div()
|
.size_full()
|
||||||
.size_full()
|
.flex()
|
||||||
.flex()
|
.items_center()
|
||||||
.items_center()
|
.justify_center()
|
||||||
.justify_center()
|
.child(Indicator::new().small()),
|
||||||
.child(Indicator::new().small()),
|
)
|
||||||
)
|
})
|
||||||
} else {
|
.when(!self.loading, |this| {
|
||||||
this.child(
|
let avatar = self.profile.avatar_url(true);
|
||||||
div()
|
let name = self.profile.display_name();
|
||||||
.h_full()
|
|
||||||
.flex()
|
this.child(
|
||||||
.items_center()
|
h_flex()
|
||||||
.justify_center()
|
.h_full()
|
||||||
.gap_2()
|
.justify_center()
|
||||||
.child(shared_t!("onboarding.choose_account"))
|
.gap_2()
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(
|
.child(Avatar::new(avatar).size(rems(1.5)))
|
||||||
Avatar::new(self.profile.avatar_url(true))
|
.child(div().pb_px().font_semibold().child(name)),
|
||||||
.size(rems(1.5)),
|
)
|
||||||
)
|
.child(SharedString::from("-"))
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.pb_px()
|
.text_xs()
|
||||||
.font_semibold()
|
.when(self.is_bunker, |this| {
|
||||||
.child(self.profile.display_name()),
|
this.child(SharedString::from("Nostr Connect"))
|
||||||
),
|
})
|
||||||
),
|
.when(self.is_extension, |this| {
|
||||||
)
|
this.child(SharedString::from("Extension"))
|
||||||
}
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.hover(|this| this.bg(cx.theme().element_hover))
|
.hover(|this| this.bg(cx.theme().element_hover))
|
||||||
.on_click(cx.listener(move |this, _e, window, cx| {
|
.on_click(cx.listener(move |this, _e, window, cx| {
|
||||||
@@ -391,7 +390,6 @@ impl Render for Account {
|
|||||||
Button::new("logout")
|
Button::new("logout")
|
||||||
.label(t!("user.sign_out"))
|
.label(t!("user.sign_out"))
|
||||||
.ghost()
|
.ghost()
|
||||||
.disabled(self.loading)
|
|
||||||
.on_click(cx.listener(move |this, _e, window, cx| {
|
.on_click(cx.listener(move |this, _e, window, cx| {
|
||||||
this.logout(window, cx);
|
this.logout(window, cx);
|
||||||
})),
|
})),
|
||||||
|
|||||||
Reference in New Issue
Block a user