🎉 First commit (💩)
This commit is contained in:
170
src/components/login.rs
Normal file
170
src/components/login.rs
Normal file
@@ -0,0 +1,170 @@
|
||||
use dioxus::prelude::*;
|
||||
use sir::css;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::app_settings::AppSettings;
|
||||
use crate::components::avatar_selector::AvatarSelector;
|
||||
use crate::components::header::Header;
|
||||
use crate::matrix_client::{LoginStyle, MatrixClient};
|
||||
|
||||
pub fn Login(cx: Scope) -> Element {
|
||||
let app_context = use_shared_state::<AppSettings>(cx).unwrap();
|
||||
println!("app_context={:?}", app_context.read());
|
||||
|
||||
let login = use_ref(cx, || Login::new());
|
||||
|
||||
let empty_placeholder = String::from("");
|
||||
|
||||
let root = css!(
|
||||
"
|
||||
width: 90%;
|
||||
height: 98%;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
padding: 5%;
|
||||
padding-top: 2%;
|
||||
|
||||
background: linear-gradient(rgb(138, 191, 209), rgb(236, 246, 249) 10%);
|
||||
"
|
||||
);
|
||||
|
||||
let header = css!(
|
||||
"
|
||||
height: 5%;
|
||||
width: 100%;
|
||||
"
|
||||
);
|
||||
|
||||
let body = css!(
|
||||
"
|
||||
height: 50%;
|
||||
width: 50%;
|
||||
max-width: 400px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
padding-bottom: 3%;
|
||||
"
|
||||
);
|
||||
|
||||
let footer_buttons = css!(
|
||||
"
|
||||
width: 100%;
|
||||
|
||||
padding-top: 5%;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
"
|
||||
);
|
||||
|
||||
let avatar_selector = css!(
|
||||
"
|
||||
height: 30%;
|
||||
width: 100%;
|
||||
"
|
||||
);
|
||||
|
||||
let run_matrix_client = move |_| {
|
||||
to_owned![app_context, login];
|
||||
|
||||
let homeserver_url = login.read().homeserver_url.clone().unwrap();
|
||||
let username = login.read().email.clone().unwrap();
|
||||
let password = login.read().password.clone().unwrap();
|
||||
|
||||
cx.spawn(async {
|
||||
let requester = MatrixClient::spawn(homeserver_url).await;
|
||||
|
||||
requester.init();
|
||||
requester.login(LoginStyle::Password(username, password));
|
||||
|
||||
let context = app_context;
|
||||
context.write().requester = Some(Arc::new(requester));
|
||||
});
|
||||
};
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
class: "{root}",
|
||||
|
||||
div {
|
||||
class: "{header}",
|
||||
Header {},
|
||||
},
|
||||
|
||||
div {
|
||||
class: "{body}",
|
||||
div {
|
||||
class: "{avatar_selector}",
|
||||
AvatarSelector {},
|
||||
},
|
||||
|
||||
p {
|
||||
"Matrix homeserver:"
|
||||
},
|
||||
input {
|
||||
id: "input-homeserver-url",
|
||||
r#type: "text",
|
||||
name: "homeserver URL",
|
||||
value: "{(login.read().homeserver_url.as_ref().unwrap_or(&empty_placeholder))}",
|
||||
oninput: move |evt| login.write().homeserver_url = Some(evt.value.clone()),
|
||||
},
|
||||
|
||||
p {
|
||||
"E-mail address:"
|
||||
},
|
||||
input {
|
||||
id: "login-input-email",
|
||||
r#type: "text",
|
||||
name: "email",
|
||||
value: "{login.read().email.as_ref().unwrap_or(&empty_placeholder)}",
|
||||
oninput: move |evt| login.write().email = Some(evt.value.clone()),
|
||||
},
|
||||
p {
|
||||
"Password:"
|
||||
},
|
||||
input {
|
||||
id: "login-input-password",
|
||||
r#type: "password",
|
||||
name: "Password",
|
||||
value: "{login.read().password.as_ref().unwrap_or(&empty_placeholder)}",
|
||||
oninput: move |evt| login.write().password = Some(evt.value.clone()),
|
||||
},
|
||||
|
||||
div {
|
||||
class: "{footer_buttons}",
|
||||
input {
|
||||
class: "button",
|
||||
onclick: run_matrix_client,
|
||||
r#type: "submit",
|
||||
value: "sign in",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Login {
|
||||
homeserver_url: Option<String>,
|
||||
email: Option<String>,
|
||||
password: Option<String>,
|
||||
}
|
||||
|
||||
impl Login {
|
||||
fn new() -> Self {
|
||||
let login = Self {
|
||||
homeserver_url: None,
|
||||
email: None,
|
||||
password: None,
|
||||
};
|
||||
login
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user