diff --git a/src/components/main_window.rs b/src/components/main_window.rs index fb04127..badc6ec 100644 --- a/src/components/main_window.rs +++ b/src/components/main_window.rs @@ -1,14 +1,12 @@ use dioxus::prelude::*; -use dioxus_std::utils::rw::use_rw; +use dioxus_std::utils::rw::UseRw; use crate::base::Store; use crate::components::contacts_window::contacts_window::ContactsWindow; use crate::components::login::Login; #[inline_props] -pub fn MainWindow(cx: Scope) -> Element { - let rw_store = use_rw(cx, || Store::new()); - +pub fn MainWindow<'a>(cx: Scope, rw_store: &'a UseRw) -> Element { let is_logged = rw_store.read().unwrap().is_logged; cx.render(rsx! { diff --git a/src/main.rs b/src/main.rs index b25b9a4..43acc90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,25 +2,32 @@ use dioxus::prelude::*; use dioxus_desktop::Config; +use dioxus_std::utils::rw::use_rw; pub mod components; pub mod matrix_client; use crate::base::AppSettings; +use crate::base::Store; use crate::components::chats_window::chats_window::ChatsWindow; use crate::components::main_window::MainWindow; mod base; fn App(cx: Scope) -> Element { - println!("App rendering"); - use_shared_state_provider(cx, || cx.props.clone()); - let chats_window = dioxus_desktop::use_window(cx); - let chats_dom = VirtualDom::new(ChatsWindow); - let window_cfg = Config::default().with_custom_head( - r#" + let rw_store = use_rw(cx, || Store::new()); + + let is_logged = rw_store.read().unwrap().is_logged; + + let chats_win_state = use_state(cx, || None); + + if is_logged && chats_win_state.is_none() { + let chats_window = dioxus_desktop::use_window(cx); + let chats_dom = VirtualDom::new(ChatsWindow); + let window_cfg = Config::default().with_custom_head( + r#" "# - .to_owned(), - ); - chats_window.new_window(chats_dom, window_cfg); + .to_owned(), + ); + let chats_window_desktop_service = chats_window.new_window(chats_dom, window_cfg); + chats_win_state.set(Some(chats_window_desktop_service)); + } cx.render(rsx! { - MainWindow {} + MainWindow {rw_store: rw_store} }) }