diff --git a/app/src/login.rs b/app/src/login.rs index 498ab22..c781fd6 100644 --- a/app/src/login.rs +++ b/app/src/login.rs @@ -3,7 +3,8 @@ use anyhow::{anyhow, Result}; use lldap_model::*; use wasm_bindgen::JsCast; use yew::prelude::*; -use yew::services::fetch::FetchTask; +use yew::services::{fetch::FetchTask, ConsoleService}; +use yew::FocusEvent; pub struct LoginForm { link: ComponentLink, @@ -24,6 +25,13 @@ pub enum Msg { AuthenticationResponse(Result), } +impl LoginForm { + fn set_error(&mut self, error: anyhow::Error) { + ConsoleService::error(&error.to_string()); + self.error = Some(error); + } +} + impl Component for LoginForm { type Message = Msg; type Properties = Props; @@ -63,14 +71,14 @@ impl Component for LoginForm { self.link.callback(Msg::AuthenticationResponse), ) { Ok(task) => self._task = Some(task), - Err(e) => self.error = Some(e), + Err(e) => self.set_error(e), } } Msg::AuthenticationResponse(Ok(user_id)) => { self.on_logged_in.emit(user_id); } Msg::AuthenticationResponse(Err(e)) => { - self.error = Some(anyhow!("Could not log in: {}", e)); + self.set_error(anyhow!("Could not log in: {}", e)); } }; true @@ -82,7 +90,7 @@ impl Component for LoginForm { fn view(&self) -> Html { html! { -
+
@@ -91,7 +99,7 @@ impl Component for LoginForm {
- +
{ if let Some(e) = &self.error { html! { e.to_string() }