From 60f246641132c302711c2b28496d30805d3e7370 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 16 Aug 2023 21:06:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Refactor=20App=20+=20add=20an=20?= =?UTF-8?q?empty=20ChatsWindow=20in=20a=20dedicated=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chats_window/chats_window.rs | 8 ++++++++ src/components/chats_window/mod.rs | 1 + src/components/main_window.rs | 22 +++++++++++++++++++++ src/components/mod.rs | 2 ++ src/main.rs | 22 +++++++++------------ 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 src/components/chats_window/chats_window.rs create mode 100644 src/components/chats_window/mod.rs create mode 100644 src/components/main_window.rs diff --git a/src/components/chats_window/chats_window.rs b/src/components/chats_window/chats_window.rs new file mode 100644 index 0000000..e542ab2 --- /dev/null +++ b/src/components/chats_window/chats_window.rs @@ -0,0 +1,8 @@ +use dioxus::prelude::*; + +pub fn ChatsWindow(cx: Scope) -> Element { + cx.render(rsx! { + div { + } + }) +} diff --git a/src/components/chats_window/mod.rs b/src/components/chats_window/mod.rs new file mode 100644 index 0000000..42160ea --- /dev/null +++ b/src/components/chats_window/mod.rs @@ -0,0 +1 @@ +pub mod chats_window; diff --git a/src/components/main_window.rs b/src/components/main_window.rs new file mode 100644 index 0000000..fb04127 --- /dev/null +++ b/src/components/main_window.rs @@ -0,0 +1,22 @@ +use dioxus::prelude::*; +use dioxus_std::utils::rw::use_rw; + +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()); + + let is_logged = rw_store.read().unwrap().is_logged; + + cx.render(rsx! { + if is_logged { + rsx!(ContactsWindow {rw_store: rw_store}) + } + else { + rsx!(Login {rw_store: rw_store}) + } + }) +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 3b346fc..0f37658 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,4 +1,6 @@ pub mod avatar_selector; +pub mod chats_window; pub mod contacts_window; pub mod header; pub mod login; +pub mod main_window; diff --git a/src/main.rs b/src/main.rs index e702e7c..4a62dc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,31 +2,27 @@ 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, Store}; -use crate::components::contacts_window::contacts_window::ContactsWindow; -use crate::components::login::Login; +use crate::base::AppSettings; +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 rw_store = use_rw(cx, || Store::new()); - - let is_logged = rw_store.read().unwrap().is_logged; + let chats_window = dioxus_desktop::use_window(cx); + let chats_dom = VirtualDom::new(ChatsWindow); + chats_window.new_window(chats_dom, Default::default()); cx.render(rsx! { - if is_logged { - rsx!(ContactsWindow {rw_store: rw_store}) - } - else { - rsx!(Login {rw_store: rw_store}) - } + MainWindow {} }) }