🎨 Reorganize the contacts_window widgets + add first interactions with homeserver

This commit is contained in:
2023-08-15 22:05:26 +02:00
parent 22ef914304
commit 2159c6adeb
17 changed files with 712 additions and 243 deletions

View File

@@ -11,19 +11,15 @@ use crate::matrix_client::{LoginStyle, MatrixClient};
turf::style_sheet!("src/components/login.scss");
#[derive(Props)]
pub struct LoginProps<'a> {
pub store: &'a mut UseRw<Store>,
}
static EMPTY_PLACEHOLDER: &str = "Tmp placeholder";
pub fn Login<'a>(cx: Scope<'a, LoginProps<'a>>) -> Element<'a> {
#[inline_props]
pub fn Login<'a>(cx: Scope, rw_store: &'a UseRw<Store>) -> Element {
let app_context = use_shared_state::<AppSettings>(cx).unwrap();
let invalid_login = use_state(cx, || false);
let login = use_ref(cx, || Login::new());
let store = cx.props.store.clone();
let empty_placeholder = String::from("");
let arc_store = Arc::new(rw_store.to_owned().clone());
let password_class = if **invalid_login {
ClassName::INVALID_INPUT
@@ -33,14 +29,15 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps<'a>>) -> Element<'a> {
let run_matrix_client = move |_| {
cx.spawn({
to_owned![app_context, invalid_login, login, store];
to_owned![app_context, invalid_login, login, arc_store];
let homeserver_url = login.read().homeserver_url.clone().unwrap();
let username = login.read().email.clone().unwrap();
let password = login.read().password.clone().unwrap();
let login_ref = login.read();
let homeserver_url = login_ref.homeserver_url.clone().unwrap();
let username = login_ref.email.clone().unwrap();
let password = login_ref.password.clone().unwrap();
async move {
let requester = MatrixClient::spawn(homeserver_url, store).await;
let requester = MatrixClient::spawn(homeserver_url, arc_store.clone()).await;
requester.init();
match requester.login(LoginStyle::Password(username, password)) {
@@ -58,6 +55,12 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps<'a>>) -> Element<'a> {
});
};
let login_ref = login.read();
let placeholder = EMPTY_PLACEHOLDER.to_string();
let homeserver_url_value = login_ref.homeserver_url.as_ref().unwrap_or(&placeholder);
let email_value = login_ref.email.as_ref().unwrap_or(&placeholder);
let password_value = login_ref.password.as_ref().unwrap_or(&placeholder);
cx.render(rsx! {
style { STYLE_SHEET },
@@ -83,7 +86,7 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps<'a>>) -> Element<'a> {
id: "input-homeserver-url",
r#type: "text",
name: "homeserver URL",
value: "{(login.read().homeserver_url.as_ref().unwrap_or(&empty_placeholder))}",
value: "{homeserver_url_value}",
oninput: move |evt| login.write().homeserver_url = Some(evt.value.clone()),
},
@@ -94,7 +97,7 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps<'a>>) -> Element<'a> {
id: "login-input-email",
r#type: "text",
name: "email",
value: "{login.read().email.as_ref().unwrap_or(&empty_placeholder)}",
value: "{email_value}",
oninput: move |evt| login.write().email = Some(evt.value.clone()),
},
p {
@@ -105,7 +108,7 @@ pub fn Login<'a>(cx: Scope<'a, LoginProps<'a>>) -> Element<'a> {
id: "login-input-password",
r#type: "password",
name: "Password",
value: "{login.read().password.as_ref().unwrap_or(&empty_placeholder)}",
value: "{password_value}",
oninput: move |evt| {
login.write().password = Some(evt.value.clone());
invalid_login.set(false);