✨ Use of Conversations layout
This commit is contained in:
71
src/base.rs
71
src/base.rs
@@ -1,71 +0,0 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use futures_util::stream::StreamExt;
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use crate::domain::model::account::Account;
|
||||
use crate::domain::model::messaging_interface::AccountMessagingProviderInterface;
|
||||
use crate::domain::model::session::Session;
|
||||
use crate::infrastructure::messaging::matrix::client::Client;
|
||||
use crate::infrastructure::messaging::matrix::worker_tasks::LoginStyle;
|
||||
use crate::ui::store::Store;
|
||||
|
||||
pub async fn login(mut rx: UnboundedReceiver<bool>, session: &GlobalSignal<Session>) {
|
||||
while let Some(is_logged) = rx.next().await {
|
||||
error!("is_logged={is_logged}");
|
||||
if !is_logged {
|
||||
let homeserver_url = session.read().homeserver_url.clone();
|
||||
let username = session.read().username.clone();
|
||||
let password = session.read().password.clone();
|
||||
|
||||
if homeserver_url.is_some() && username.is_some() && password.is_some() {
|
||||
let (requester, account_events_receiver) =
|
||||
Client::spawn(homeserver_url.unwrap()).await;
|
||||
|
||||
if let Err(err) = requester.init().await {
|
||||
error!("Following error occureds during client init: {}", err);
|
||||
}
|
||||
|
||||
error!("Before login");
|
||||
|
||||
match requester
|
||||
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
debug!("successfully logged");
|
||||
session.write().is_logged = true;
|
||||
|
||||
let requester = Rc::new(requester);
|
||||
|
||||
dioxus::prelude::spawn(async move {
|
||||
ACCOUNT.write().set_messaging_provider(requester.clone());
|
||||
|
||||
let _ = requester
|
||||
.run_forever(&*ACCOUNT.read(), account_events_receiver)
|
||||
.await;
|
||||
});
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Error during login: {err}");
|
||||
// TODO: Handle invalid login
|
||||
// invalid_login.modify(|_| true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!("At least one of the following values is/are invalid: homeserver, username or password");
|
||||
}
|
||||
} else {
|
||||
warn!("already logged... skip login");
|
||||
}
|
||||
}
|
||||
error!("=== LOGIN END ===");
|
||||
}
|
||||
|
||||
pub static STORE: GlobalSignal<Store> = Signal::global(Store::new);
|
||||
|
||||
// TODO: Merge ACCOUNT and SESSION
|
||||
pub static ACCOUNT: GlobalSignal<Account> = Signal::global(|| Account::new(&STORE));
|
||||
pub static SESSION: GlobalSignal<Session> = Signal::global(Session::new);
|
131
src/main.rs
131
src/main.rs
@@ -8,12 +8,22 @@ mod infrastructure;
|
||||
mod ui;
|
||||
mod utils;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use tracing::{debug, error};
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use futures_util::stream::StreamExt;
|
||||
use tracing::{debug, error, warn};
|
||||
use tracing_forest::ForestLayer;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use tracing_subscriber::{prelude::*, EnvFilter};
|
||||
|
||||
use crate::{
|
||||
domain::model::{messaging_interface::AccountMessagingProviderInterface, session::Session},
|
||||
infrastructure::messaging::matrix::{client::Client, worker_tasks::LoginStyle},
|
||||
ui::{
|
||||
layouts::{conversations::Conversations, login::Login},
|
||||
ACCOUNT, SESSION,
|
||||
},
|
||||
};
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_family = "wasm")] {
|
||||
@@ -26,80 +36,65 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
use crate::base::{login, sync_rooms};
|
||||
use crate::base::{APP_SETTINGS, ROOMS, SESSION};
|
||||
use crate::ui::components::login::Login;
|
||||
use crate::ui::components::main_window::MainWindow;
|
||||
use crate::ui::layouts::login::Login;
|
||||
async fn login(mut rx: UnboundedReceiver<bool>, session: &GlobalSignal<Session>) {
|
||||
while let Some(is_logged) = rx.next().await {
|
||||
if !is_logged {
|
||||
let homeserver_url = session.read().homeserver_url.clone();
|
||||
let username = session.read().username.clone();
|
||||
let password = session.read().password.clone();
|
||||
|
||||
mod base;
|
||||
if homeserver_url.is_some() && username.is_some() && password.is_some() {
|
||||
let (requester, account_events_receiver) =
|
||||
Client::spawn(homeserver_url.unwrap()).await;
|
||||
|
||||
if let Err(err) = requester.init().await {
|
||||
warn!("Unable to login: {}", err);
|
||||
}
|
||||
|
||||
match requester
|
||||
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
debug!("successfully logged");
|
||||
session.write().is_logged = true;
|
||||
|
||||
let requester = Rc::new(requester);
|
||||
|
||||
dioxus::prelude::spawn(async move {
|
||||
ACCOUNT.write().set_messaging_provider(requester.clone());
|
||||
|
||||
let _ = requester
|
||||
.run_forever(&*ACCOUNT.read(), account_events_receiver)
|
||||
.await;
|
||||
});
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Error during login: {err}");
|
||||
// TODO: Handle invalid login
|
||||
// invalid_login.modify(|_| true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!("At least one of the following values is/are invalid: homeserver, username or password");
|
||||
}
|
||||
} else {
|
||||
warn!("already logged... skip login");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
debug!("*** App rendering ***");
|
||||
|
||||
let login_coro = use_coroutine(|rx| login(rx, &APP_SETTINGS, &SESSION));
|
||||
|
||||
let mut sync_rooms_coro = None;
|
||||
|
||||
if let Some(requester) = &APP_SETTINGS.read().requester {
|
||||
sync_rooms_coro = Some(use_coroutine(|rx| {
|
||||
sync_rooms(rx, requester.borrow().receivers.clone(), &ROOMS)
|
||||
}));
|
||||
}
|
||||
let login_coro = use_coroutine(|rx| login(rx, &SESSION));
|
||||
|
||||
if !SESSION.read().is_logged {
|
||||
login_coro.send(false);
|
||||
} else {
|
||||
if let Some(coro) = sync_rooms_coro {
|
||||
coro.send(true);
|
||||
}
|
||||
|
||||
// if chats_win_state.read().is_none() {
|
||||
// let chats_window = dioxus_desktop::use_window(cx);
|
||||
|
||||
// let receivers = app_settings
|
||||
// .read()
|
||||
// .requester
|
||||
// .as_ref()
|
||||
// .unwrap()
|
||||
// .borrow()
|
||||
// .receivers
|
||||
// .clone();
|
||||
|
||||
// let chats_props = ChatsWindowProps {
|
||||
// receivers,
|
||||
// interface: chats_win_interface_ref.clone(),
|
||||
// };
|
||||
|
||||
// let chats_dom = VirtualDom::new_with_props(ChatsWindow, chats_props);
|
||||
|
||||
// let window_cfg = Config::default().with_custom_head(
|
||||
// r#"
|
||||
// <style type="text/css">
|
||||
// html, body {
|
||||
// height: 100%;
|
||||
// width: 100%;
|
||||
|
||||
// margin: 0;
|
||||
// }
|
||||
// #main, #bodywrap {
|
||||
// height: 100%;
|
||||
// width: 100%;
|
||||
// }
|
||||
// </style>
|
||||
// "#
|
||||
// .to_owned(),
|
||||
// );
|
||||
|
||||
// let chats_window_desktop_service = chats_window.new_window(chats_dom, window_cfg);
|
||||
// chats_win_state.set(Some(chats_window_desktop_service));
|
||||
// }
|
||||
}
|
||||
|
||||
if SESSION.read().is_logged {
|
||||
debug!("Should render the MainWindow component");
|
||||
rsx! {
|
||||
MainWindow {},
|
||||
Conversations {}
|
||||
}
|
||||
} else {
|
||||
rsx! {
|
||||
|
@@ -4,9 +4,11 @@ use tracing::{debug, trace, warn};
|
||||
|
||||
use super::{button::Button, icons::SearchIcon, text_input::TextInput};
|
||||
use crate::{
|
||||
base::{ACCOUNT, STORE},
|
||||
domain::model::{common::PresenceState as DomainPresenceState, room::RoomId, space::SpaceId},
|
||||
ui::components::icons::{ChatsIcon, LogoIcon, RoomsIcon, SpacesIcon},
|
||||
ui::{
|
||||
components::icons::{ChatsIcon, LogoIcon, RoomsIcon, SpacesIcon},
|
||||
ACCOUNT, STORE,
|
||||
},
|
||||
};
|
||||
|
||||
turf::style_sheet!("src/ui/components/conversations.scss");
|
||||
|
@@ -1,7 +1,4 @@
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::{borrow::Cow, cell::RefCell, collections::HashMap, rc::Rc};
|
||||
|
||||
use const_format::formatcp;
|
||||
use dioxus::prelude::*;
|
||||
@@ -9,16 +6,18 @@ use tracing::{debug, error, warn};
|
||||
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
|
||||
use zxcvbn::zxcvbn;
|
||||
|
||||
use crate::base::SESSION;
|
||||
use crate::domain::model::session::Session;
|
||||
use crate::infrastructure::services::random_svg_generators::{
|
||||
generate_random_svg_shape, ShapeConfig,
|
||||
use crate::{
|
||||
domain::model::session::Session,
|
||||
infrastructure::services::random_svg_generators::{generate_random_svg_shape, ShapeConfig},
|
||||
ui::SESSION,
|
||||
};
|
||||
|
||||
use super::button::{LoginButton, RegisterButton};
|
||||
use super::modal::{Modal, Severity};
|
||||
use super::spinner::Spinner;
|
||||
use super::text_input::{PasswordInputState, PasswordTextInput, TextInput, TextInputState};
|
||||
use super::{
|
||||
button::{LoginButton, RegisterButton},
|
||||
modal::{Modal, Severity},
|
||||
spinner::Spinner,
|
||||
text_input::{PasswordInputState, PasswordTextInput, TextInput, TextInputState},
|
||||
};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/style_vars.rs"));
|
||||
|
||||
|
@@ -1,3 +1,13 @@
|
||||
pub(crate) mod components;
|
||||
pub(crate) mod layouts;
|
||||
pub(crate) mod store;
|
||||
|
||||
use dioxus::prelude::{GlobalSignal, Signal};
|
||||
|
||||
use super::domain::model::{account::Account, session::Session};
|
||||
use store::Store;
|
||||
|
||||
pub static STORE: GlobalSignal<Store> = Signal::global(Store::new);
|
||||
// TODO: Merge ACCOUNT and SESSION
|
||||
pub static ACCOUNT: GlobalSignal<Account> = Signal::global(|| Account::new(&STORE));
|
||||
pub static SESSION: GlobalSignal<Session> = Signal::global(Session::new);
|
||||
|
Reference in New Issue
Block a user