✨ Add Login component
This commit is contained in:
41
src/main.rs
41
src/main.rs
@@ -7,10 +7,13 @@ pub mod utils;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::Config;
|
||||
use fermi::*;
|
||||
use tokio::time::{sleep, Duration};
|
||||
use tracing::{debug, Level};
|
||||
|
||||
use crate::base::{login, sync_rooms, APP_SETTINGS, CHATS_WIN_INTERFACE, ROOMS, SESSION};
|
||||
use crate::components::chats_window::{ChatsWindow, ChatsWindowProps};
|
||||
use crate::components::loading::LoadingPage;
|
||||
use crate::components::login::Login;
|
||||
use crate::components::main_window::MainWindow;
|
||||
|
||||
mod base;
|
||||
@@ -25,6 +28,20 @@ fn App(cx: Scope) -> Element {
|
||||
let rooms_ref = use_atom_ref(cx, &ROOMS);
|
||||
let chats_win_interface_ref = use_atom_ref(cx, &CHATS_WIN_INTERFACE);
|
||||
|
||||
let ready = use_state(cx, || false);
|
||||
|
||||
// Dummy timer simulating the loading of the application
|
||||
let _: &Coroutine<()> = use_coroutine(cx, |_: UnboundedReceiver<_>| {
|
||||
to_owned![ready];
|
||||
async move {
|
||||
debug!("Not ready");
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
// sleep(Duration::from_secs(0)).await;
|
||||
debug!("Ready");
|
||||
ready.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
let chats_win_state = use_state(cx, || None);
|
||||
|
||||
let login_coro = use_coroutine(cx, |rx| {
|
||||
@@ -88,13 +105,25 @@ fn App(cx: Scope) -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
cx.render(rsx! {
|
||||
MainWindow {}
|
||||
})
|
||||
if **ready {
|
||||
if session_ref.read().is_logged {
|
||||
debug!("Should render the MainWindow component");
|
||||
cx.render(rsx! {
|
||||
MainWindow {},
|
||||
})
|
||||
} else {
|
||||
cx.render(rsx! {
|
||||
Login {},
|
||||
})
|
||||
}
|
||||
} else {
|
||||
cx.render(rsx! {
|
||||
LoadingPage {},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
// .pretty()
|
||||
.with_max_level(Level::DEBUG)
|
||||
@@ -102,6 +131,4 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
dioxus_desktop::launch(App);
|
||||
// dioxus_web::launch(App);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user