⬆️ Update the components to take the dioxus 0.5 rework into account

This commit is contained in:
2024-03-31 23:26:10 +02:00
parent aad0064a0c
commit 9071b0073c
26 changed files with 537 additions and 534 deletions

View File

@@ -5,121 +5,105 @@ pub mod matrix_interface;
pub mod utils;
use dioxus::prelude::*;
use dioxus_desktop::Config;
use fermi::*;
use tokio::time::{sleep, Duration};
use tracing::{debug, Level};
use crate::base::{login, sync_rooms, APP_SETTINGS, CHATS_WIN_INTERFACE, ROOMS, SESSION};
use crate::components::chats_window::{ChatsWindow, ChatsWindowProps};
use crate::base::{login, sync_rooms};
use crate::base::{APP_SETTINGS, ROOMS, SESSION};
use crate::components::loading::LoadingPage;
use crate::components::login::Login;
use crate::components::main_window::MainWindow;
mod base;
fn App(cx: Scope) -> Element {
fn app() -> Element {
debug!("*** App rendering ***");
use_init_atom_root(cx);
let app_settings_ref = use_atom_ref(cx, &APP_SETTINGS);
let session_ref = use_atom_ref(cx, &SESSION);
let rooms_ref = use_atom_ref(cx, &ROOMS);
let chats_win_interface_ref = use_atom_ref(cx, &CHATS_WIN_INTERFACE);
let ready = use_state(cx, || false);
let mut ready = use_signal(|| false);
// Dummy timer simulating the loading of the application
let _: &Coroutine<()> = use_coroutine(cx, |_: UnboundedReceiver<_>| {
to_owned![ready];
async move {
debug!("Not ready");
sleep(Duration::from_secs(3)).await;
// sleep(Duration::from_secs(0)).await;
debug!("Ready");
ready.set(true);
}
let _: Coroutine<()> = use_coroutine(|_: UnboundedReceiver<_>| async move {
debug!("Not ready");
sleep(Duration::from_secs(3)).await;
// sleep(Duration::from_secs(0)).await;
debug!("Ready");
ready.set(true);
});
let chats_win_state = use_state(cx, || None);
let login_coro = use_coroutine(cx, |rx| {
login(rx, app_settings_ref.clone(), session_ref.clone())
});
let login_coro = use_coroutine(|rx| login(rx, &APP_SETTINGS, &SESSION));
let mut sync_rooms_coro = None;
if let Some(requester) = &app_settings_ref.read().requester {
sync_rooms_coro = Some(use_coroutine(cx, |rx| {
sync_rooms(rx, requester.borrow().receivers.clone(), rooms_ref.clone())
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_ref.read().is_logged {
if !SESSION.read().is_logged {
login_coro.send(false);
} else {
if let Some(coro) = sync_rooms_coro {
coro.send(true);
}
if chats_win_state.is_none() {
let chats_window = dioxus_desktop::use_window(cx);
// if chats_win_state.read().is_none() {
// let chats_window = dioxus_desktop::use_window(cx);
let receivers = app_settings_ref
.read()
.requester
.as_ref()
.unwrap()
.borrow()
.receivers
.clone();
// 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_props = ChatsWindowProps {
// receivers,
// interface: chats_win_interface_ref.clone(),
// };
let chats_dom = VirtualDom::new_with_props(ChatsWindow, chats_props);
// 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%;
// 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(),
);
// 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));
}
// let chats_window_desktop_service = chats_window.new_window(chats_dom, window_cfg);
// chats_win_state.set(Some(chats_window_desktop_service));
// }
}
if **ready {
if session_ref.read().is_logged {
if *ready.read() {
if SESSION.read().is_logged {
debug!("Should render the MainWindow component");
cx.render(rsx! {
rsx! {
MainWindow {},
})
}
} else {
cx.render(rsx! {
rsx! {
Login {},
})
}
}
} else {
cx.render(rsx! {
rsx! {
LoadingPage {},
})
}
}
}
@@ -129,6 +113,5 @@ fn main() {
.with_max_level(Level::DEBUG)
.init();
dioxus_desktop::launch(App);
// dioxus_web::launch(App);
launch(app);
}