Switch to Cows in login page to store both &'static str and String
This commit is contained in:
parent
415236a53c
commit
eee42be44b
@ -185,7 +185,7 @@ impl Component for ChatPage {
|
|||||||
.push_with_query(
|
.push_with_query(
|
||||||
&Route::Login,
|
&Route::Login,
|
||||||
&LoginQuery {
|
&LoginQuery {
|
||||||
redirect: "/chat".to_string(),
|
redirect: "/chat".into(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -22,7 +22,7 @@ pub fn Home() -> Html {
|
|||||||
.push_with_query(
|
.push_with_query(
|
||||||
&Route::Login,
|
&Route::Login,
|
||||||
&LoginQuery {
|
&LoginQuery {
|
||||||
redirect: "/".to_string(),
|
redirect: "/".into(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::components::Nav;
|
use crate::components::Nav;
|
||||||
use common::{LoggedInResponse, LoginRequest, LoginResponse};
|
use common::{LoggedInResponse, LoginRequest, LoginResponse};
|
||||||
use gloo::{
|
use gloo::{
|
||||||
@ -12,13 +14,13 @@ use yew_hooks::use_mount;
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct LoginQuery {
|
pub struct LoginQuery {
|
||||||
pub redirect: String,
|
pub redirect: Cow<'static, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LoginQuery {
|
impl Default for LoginQuery {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
redirect: "/".to_string(),
|
redirect: "/".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,7 +31,7 @@ pub fn Login() -> Html {
|
|||||||
let username_ref = use_node_ref();
|
let username_ref = use_node_ref();
|
||||||
let password_ref = use_node_ref();
|
let password_ref = use_node_ref();
|
||||||
let disable_input = use_state(|| false);
|
let disable_input = use_state(|| false);
|
||||||
let login_error = use_state(|| None);
|
let login_error = use_state(|| Option::<Cow<'static, str>>::None);
|
||||||
let query_params = BrowserHistory::new()
|
let query_params = BrowserHistory::new()
|
||||||
.location()
|
.location()
|
||||||
.query::<LoginQuery>()
|
.query::<LoginQuery>()
|
||||||
@ -67,7 +69,7 @@ pub fn Login() -> Html {
|
|||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(format!("Could not send login request to server: {err}"));
|
error!(format!("Could not send login request to server: {err}"));
|
||||||
login_error.set(Some("Error logging in".to_string()));
|
login_error.set(Some("Error logging in".into()));
|
||||||
disable_input.set(false);
|
disable_input.set(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -76,15 +78,15 @@ pub fn Login() -> Html {
|
|||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(format!("Could not parse login response: {err}"));
|
error!(format!("Could not parse login response: {err}"));
|
||||||
login_error.set(Some("Error logging in".to_string()));
|
login_error.set(Some("Error logging in".into()));
|
||||||
disable_input.set(false);
|
disable_input.set(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match resp {
|
match resp {
|
||||||
Ok(_) => BrowserHistory::new().push(&redirect),
|
Ok(_) => BrowserHistory::new().push(redirect),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
login_error.set(Some(err));
|
login_error.set(Some(err.into()));
|
||||||
password_ref
|
password_ref
|
||||||
.cast::<HtmlInputElement>()
|
.cast::<HtmlInputElement>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -121,7 +123,7 @@ pub fn Login() -> Html {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if resp.logged_in {
|
if resp.logged_in {
|
||||||
BrowserHistory::new().push(&redirect);
|
BrowserHistory::new().push(redirect);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user