Got log in and out working, moved global state
All checks were successful
Build Crate / build (push) Successful in 1m45s
All checks were successful
Build Crate / build (push) Successful in 1m45s
close to done!
This commit is contained in:
@@ -6,7 +6,7 @@ use web_sys::Event;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::templates::global_state::AppStateRx;
|
||||
use crate::global_state::AppStateRx;
|
||||
use crate::templates::get_api_path;
|
||||
use chrono::Utc;
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// Not a page, global state that is shared between all pages
|
||||
|
||||
use perseus::{prelude::*, state::GlobalStateCreator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
models::auth::Claims,
|
||||
state_enums::{LoginState, OpenState},
|
||||
};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(engine)] {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||
#[rx(alias = "AppStateRx")]
|
||||
pub struct AppState {
|
||||
#[rx(nested)]
|
||||
pub auth: AuthData,
|
||||
#[rx(nested)]
|
||||
pub modals_open: ModalOpenData,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||
#[rx(alias = "AuthDataRx")]
|
||||
pub struct AuthData {
|
||||
pub state: LoginState,
|
||||
pub username: Option<String>,
|
||||
pub claims: Claims,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||
#[rx(alias = "ModalOpenDataRx")]
|
||||
pub struct ModalOpenData {
|
||||
pub login: OpenState,
|
||||
}
|
||||
|
||||
pub fn get_global_state_creator() -> GlobalStateCreator {
|
||||
GlobalStateCreator::new().build_state_fn(get_build_state)
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
pub async fn get_build_state() -> AppState {
|
||||
AppState {
|
||||
auth: AuthData {
|
||||
state: LoginState::Unknown,
|
||||
username: None,
|
||||
claims: Claims {
|
||||
sub: "".to_owned(),
|
||||
exp: 0,
|
||||
},
|
||||
},
|
||||
modals_open: ModalOpenData {
|
||||
login: OpenState::Closed,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Client only code to check if they're authenticated
|
||||
#[cfg(client)]
|
||||
impl AuthDataRx {
|
||||
pub fn detect_state(&self) {
|
||||
// If the user is in a known state, return
|
||||
if let LoginState::Authenticated | LoginState::NotAuthenticated = *self.state.get() {
|
||||
return;
|
||||
}
|
||||
// TODO -> Get state from storage
|
||||
self.state.set(LoginState::NotAuthenticated);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
pub mod add_game_form;
|
||||
pub mod global_state;
|
||||
pub mod index;
|
||||
pub mod one_v_one_board;
|
||||
pub mod overall_board;
|
||||
@@ -7,7 +6,6 @@ pub mod overall_board;
|
||||
#[cfg(client)]
|
||||
use perseus::utils::get_path_prefix_client;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_api_path(path: &str) -> String {
|
||||
#[cfg(engine)]
|
||||
{
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use crate::{
|
||||
components::layout::Layout, state_enums::GameState, templates::global_state::AppStateRx,
|
||||
};
|
||||
use crate::{components::layout::Layout, global_state::AppStateRx, state_enums::GameState};
|
||||
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
Reference in New Issue
Block a user