✨ 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 ui;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use std::rc::Rc;
|
||||||
use tracing::{debug, error};
|
|
||||||
|
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use futures_util::stream::StreamExt;
|
||||||
|
use tracing::{debug, error, warn};
|
||||||
use tracing_forest::ForestLayer;
|
use tracing_forest::ForestLayer;
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::{prelude::*, EnvFilter};
|
||||||
use tracing_subscriber::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! {
|
cfg_if! {
|
||||||
if #[cfg(target_family = "wasm")] {
|
if #[cfg(target_family = "wasm")] {
|
||||||
@@ -26,80 +36,65 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::base::{login, sync_rooms};
|
async fn login(mut rx: UnboundedReceiver<bool>, session: &GlobalSignal<Session>) {
|
||||||
use crate::base::{APP_SETTINGS, ROOMS, SESSION};
|
while let Some(is_logged) = rx.next().await {
|
||||||
use crate::ui::components::login::Login;
|
if !is_logged {
|
||||||
use crate::ui::components::main_window::MainWindow;
|
let homeserver_url = session.read().homeserver_url.clone();
|
||||||
use crate::ui::layouts::login::Login;
|
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 {
|
fn app() -> Element {
|
||||||
debug!("*** App rendering ***");
|
let login_coro = use_coroutine(|rx| login(rx, &SESSION));
|
||||||
|
|
||||||
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)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if !SESSION.read().is_logged {
|
if !SESSION.read().is_logged {
|
||||||
login_coro.send(false);
|
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 {
|
if SESSION.read().is_logged {
|
||||||
debug!("Should render the MainWindow component");
|
|
||||||
rsx! {
|
rsx! {
|
||||||
MainWindow {},
|
Conversations {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rsx! {
|
rsx! {
|
||||||
|
@@ -4,9 +4,11 @@ use tracing::{debug, trace, warn};
|
|||||||
|
|
||||||
use super::{button::Button, icons::SearchIcon, text_input::TextInput};
|
use super::{button::Button, icons::SearchIcon, text_input::TextInput};
|
||||||
use crate::{
|
use crate::{
|
||||||
base::{ACCOUNT, STORE},
|
|
||||||
domain::model::{common::PresenceState as DomainPresenceState, room::RoomId, space::SpaceId},
|
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");
|
turf::style_sheet!("src/ui/components/conversations.scss");
|
||||||
|
@@ -1,7 +1,4 @@
|
|||||||
use std::borrow::Cow;
|
use std::{borrow::Cow, cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use const_format::formatcp;
|
use const_format::formatcp;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
@@ -9,16 +6,18 @@ use tracing::{debug, error, warn};
|
|||||||
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
|
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
|
||||||
use zxcvbn::zxcvbn;
|
use zxcvbn::zxcvbn;
|
||||||
|
|
||||||
use crate::base::SESSION;
|
use crate::{
|
||||||
use crate::domain::model::session::Session;
|
domain::model::session::Session,
|
||||||
use crate::infrastructure::services::random_svg_generators::{
|
infrastructure::services::random_svg_generators::{generate_random_svg_shape, ShapeConfig},
|
||||||
generate_random_svg_shape, ShapeConfig,
|
ui::SESSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::button::{LoginButton, RegisterButton};
|
use super::{
|
||||||
use super::modal::{Modal, Severity};
|
button::{LoginButton, RegisterButton},
|
||||||
use super::spinner::Spinner;
|
modal::{Modal, Severity},
|
||||||
use super::text_input::{PasswordInputState, PasswordTextInput, TextInput, TextInputState};
|
spinner::Spinner,
|
||||||
|
text_input::{PasswordInputState, PasswordTextInput, TextInput, TextInputState},
|
||||||
|
};
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/style_vars.rs"));
|
include!(concat!(env!("OUT_DIR"), "/style_vars.rs"));
|
||||||
|
|
||||||
|
@@ -1,3 +1,13 @@
|
|||||||
pub(crate) mod components;
|
pub(crate) mod components;
|
||||||
pub(crate) mod layouts;
|
pub(crate) mod layouts;
|
||||||
pub(crate) mod store;
|
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