💄 Display ChatsWindow only once the user logged
This commit is contained in:
@@ -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<Store>) -> Element {
|
||||
let is_logged = rw_store.read().unwrap().is_logged;
|
||||
|
||||
cx.render(rsx! {
|
||||
|
29
src/main.rs
29
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<AppSettings>) -> 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#"
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
height: 100%;
|
||||
@@ -34,12 +41,14 @@ fn App(cx: Scope<AppSettings>) -> Element {
|
||||
}
|
||||
</style>
|
||||
"#
|
||||
.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}
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user