Migrate auth popup to AsyncWidget

This commit is contained in:
Joscha 2023-04-13 01:51:52 +02:00
parent e358e2184e
commit 03766802fd
2 changed files with 16 additions and 18 deletions

View file

@ -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<Room>,
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

View file

@ -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())