💄 Display ChatsWindow only once the user logged

This commit is contained in:
2023-08-21 21:43:42 +02:00
parent f79bf329a5
commit 4988054dae
2 changed files with 21 additions and 14 deletions

View File

@@ -1,14 +1,12 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_std::utils::rw::use_rw; use dioxus_std::utils::rw::UseRw;
use crate::base::Store; use crate::base::Store;
use crate::components::contacts_window::contacts_window::ContactsWindow; use crate::components::contacts_window::contacts_window::ContactsWindow;
use crate::components::login::Login; use crate::components::login::Login;
#[inline_props] #[inline_props]
pub fn MainWindow(cx: Scope) -> Element { pub fn MainWindow<'a>(cx: Scope, rw_store: &'a UseRw<Store>) -> Element {
let rw_store = use_rw(cx, || Store::new());
let is_logged = rw_store.read().unwrap().is_logged; let is_logged = rw_store.read().unwrap().is_logged;
cx.render(rsx! { cx.render(rsx! {

View File

@@ -2,21 +2,28 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_desktop::Config; use dioxus_desktop::Config;
use dioxus_std::utils::rw::use_rw;
pub mod components; pub mod components;
pub mod matrix_client; pub mod matrix_client;
use crate::base::AppSettings; use crate::base::AppSettings;
use crate::base::Store;
use crate::components::chats_window::chats_window::ChatsWindow; use crate::components::chats_window::chats_window::ChatsWindow;
use crate::components::main_window::MainWindow; use crate::components::main_window::MainWindow;
mod base; mod base;
fn App(cx: Scope<AppSettings>) -> Element { fn App(cx: Scope<AppSettings>) -> Element {
println!("App rendering");
use_shared_state_provider(cx, || cx.props.clone()); use_shared_state_provider(cx, || cx.props.clone());
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_window = dioxus_desktop::use_window(cx);
let chats_dom = VirtualDom::new(ChatsWindow); let chats_dom = VirtualDom::new(ChatsWindow);
let window_cfg = Config::default().with_custom_head( let window_cfg = Config::default().with_custom_head(
@@ -36,10 +43,12 @@ fn App(cx: Scope<AppSettings>) -> Element {
"# "#
.to_owned(), .to_owned(),
); );
chats_window.new_window(chats_dom, window_cfg); 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! { cx.render(rsx! {
MainWindow {} MainWindow {rw_store: rw_store}
}) })
} }