From 03766802fde92603907b4a87a190ed219ba16299 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 13 Apr 2023 01:51:52 +0200 Subject: [PATCH] Migrate auth popup to AsyncWidget --- src/ui/euph/auth.rs | 27 ++++++++++++++------------- src/ui/euph/room.rs | 7 ++----- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/ui/euph/auth.rs b/src/ui/euph/auth.rs index 682d967..f13cbc4 100644 --- a/src/ui/euph/auth.rs +++ b/src/ui/euph/auth.rs @@ -1,26 +1,27 @@ -use toss::Terminal; +use toss::widgets::{BoxedAsync, EditorState}; +use toss::{Terminal, WidgetExt}; use crate::euph::Room; use crate::ui::input::{key, InputEvent, KeyBindingsList}; -use crate::ui::util; -use crate::ui::widgets::editor::EditorState; -use crate::ui::widgets::popup::Popup; -use crate::ui::widgets::BoxedWidget; +use crate::ui::widgets2::Popup; +use crate::ui::{util2, UiError}; pub fn new() -> EditorState { EditorState::new() } -pub fn widget(editor: &EditorState) -> BoxedWidget { - Popup::new(editor.widget().hidden()) - .title("Enter password") - .build() +pub fn widget(editor: &mut EditorState) -> BoxedAsync<'_, UiError> { + Popup::new( + editor.widget().with_hidden_default_placeholder(), + "Enter password", + ) + .boxed_async() } pub fn list_key_bindings(bindings: &mut KeyBindingsList) { bindings.binding("esc", "abort"); bindings.binding("enter", "authenticate"); - util::list_editor_key_bindings(bindings, |_| true); + util2::list_editor_key_bindings(bindings, |_| true); } pub enum EventResult { @@ -33,18 +34,18 @@ pub fn handle_input_event( terminal: &mut Terminal, event: &InputEvent, room: &Option, - editor: &EditorState, + editor: &mut EditorState, ) -> EventResult { match event { key!(Esc) => EventResult::ResetState, key!(Enter) => { if let Some(room) = &room { - let _ = room.auth(editor.text()); + let _ = room.auth(editor.text().to_string()); } EventResult::ResetState } _ => { - if util::handle_editor_input_event(editor, terminal, event, |_| true) { + if util2::handle_editor_input_event(editor, terminal, event, |_| true) { EventResult::Handled } else { EventResult::NotHandled diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs index 71f28f5..12c2f0c 100644 --- a/src/ui/euph/room.rs +++ b/src/ui/euph/room.rs @@ -16,7 +16,6 @@ use crate::euph; use crate::macros::logging_unwrap; use crate::ui::chat::{ChatState, Reaction}; use crate::ui::input::{key, InputEvent, KeyBindingsList}; -use crate::ui::widgets::editor::EditorState as OldEditorState; use crate::ui::widgets::WidgetWrapper; use crate::ui::widgets2::ListState; use crate::ui::{util2, UiError, UiEvent}; @@ -36,7 +35,7 @@ enum Focus { #[allow(clippy::large_enum_variant)] enum State { Normal, - Auth(OldEditorState), + Auth(EditorState), Nick(EditorState), Account(AccountUiState), Links(LinksState), @@ -225,9 +224,7 @@ impl EuphRoom { match &mut self.state { State::Normal => {} - State::Auth(editor) => { - layers.push(WidgetWrapper::new(auth::widget(editor)).boxed_async()) - } + State::Auth(editor) => layers.push(auth::widget(editor)), State::Nick(editor) => layers.push(nick::widget(editor)), State::Account(account) => { layers.push(WidgetWrapper::new(account.widget()).boxed_async())