🎨 Refactor App + add an empty ChatsWindow in a dedicated window

This commit is contained in:
2023-08-16 21:06:28 +02:00
parent 2159c6adeb
commit 60f2466411
5 changed files with 42 additions and 13 deletions

View File

@@ -0,0 +1,8 @@
use dioxus::prelude::*;
pub fn ChatsWindow(cx: Scope) -> Element {
cx.render(rsx! {
div {
}
})
}

View File

@@ -0,0 +1 @@
pub mod chats_window;

View File

@@ -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})
}
})
}

View File

@@ -1,4 +1,6 @@
pub mod avatar_selector; pub mod avatar_selector;
pub mod chats_window;
pub mod contacts_window; pub mod contacts_window;
pub mod header; pub mod header;
pub mod login; pub mod login;
pub mod main_window;

View File

@@ -2,31 +2,27 @@
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, Store}; use crate::base::AppSettings;
use crate::components::contacts_window::contacts_window::ContactsWindow; use crate::components::chats_window::chats_window::ChatsWindow;
use crate::components::login::Login; 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 chats_window = dioxus_desktop::use_window(cx);
let chats_dom = VirtualDom::new(ChatsWindow);
let is_logged = rw_store.read().unwrap().is_logged; chats_window.new_window(chats_dom, Default::default());
cx.render(rsx! { cx.render(rsx! {
if is_logged { MainWindow {}
rsx!(ContactsWindow {rw_store: rw_store})
}
else {
rsx!(Login {rw_store: rw_store})
}
}) })
} }