✨ First try of making reactive state external using UseRw
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -1,12 +1,12 @@
|
||||
#![allow(non_snake_case)]
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::Config;
|
||||
use dioxus_std::utils::rw::use_rw;
|
||||
|
||||
pub mod app_settings;
|
||||
pub mod components;
|
||||
pub mod matrix_client;
|
||||
|
||||
use crate::app_settings::AppSettings;
|
||||
use crate::base::{AppSettings, Store};
|
||||
use crate::components::contacts_window::ContactWindow;
|
||||
use crate::components::login::Login;
|
||||
|
||||
@@ -15,18 +15,16 @@ mod base;
|
||||
fn App(cx: Scope<AppSettings>) -> Element {
|
||||
use_shared_state_provider(cx, || cx.props.clone());
|
||||
|
||||
let app_context = use_shared_state::<AppSettings>(cx).unwrap();
|
||||
let store = use_rw(cx, || Store::new());
|
||||
|
||||
// let window = dioxus_desktop::use_window(cx);
|
||||
// let dom = VirtualDom::new(ControlWindow);
|
||||
// window.new_window(dom, cx.props.clone());
|
||||
let is_logged = store.read().unwrap().is_logged;
|
||||
|
||||
cx.render(rsx! {
|
||||
if app_context.read().store.is_logged {
|
||||
if is_logged {
|
||||
rsx!(ContactWindow {})
|
||||
}
|
||||
else {
|
||||
rsx!(Login {})
|
||||
rsx!(Login {store: store})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user