This commit is contained in:
@@ -70,10 +70,10 @@ pub fn main<G: Html>() -> PerseusApp<G> {
|
|||||||
|
|
||||||
PerseusApp::new()
|
PerseusApp::new()
|
||||||
.global_state_creator(crate::global_state::get_global_state_creator())
|
.global_state_creator(crate::global_state::get_global_state_creator())
|
||||||
.template(crate::templates::index::get_template())
|
.template(crate::templates::pool::index::get_template())
|
||||||
.template(crate::templates::add_game_form::get_template())
|
.template(crate::templates::pool::add_game_form::get_template())
|
||||||
.template(crate::templates::one_v_one_board::get_template())
|
.template(crate::templates::pool::one_v_one_board::get_template())
|
||||||
.template(crate::templates::overall_board::get_template())
|
.template(crate::templates::pool::overall_board::get_template())
|
||||||
.capsule_ref(&*crate::capsules::login_form::LOGIN_FORM)
|
.capsule_ref(&*crate::capsules::login_form::LOGIN_FORM)
|
||||||
.capsule_ref(&*crate::capsules::forgot_password_form::FORGOT_PASSWORD_FORM)
|
.capsule_ref(&*crate::capsules::forgot_password_form::FORGOT_PASSWORD_FORM)
|
||||||
.capsule_ref(&*crate::capsules::register_form::REGISTER_FORM)
|
.capsule_ref(&*crate::capsules::register_form::REGISTER_FORM)
|
||||||
|
|||||||
@@ -1,66 +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},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[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,14 +1,21 @@
|
|||||||
pub mod add_game_form;
|
pub mod pickleball;
|
||||||
pub mod index;
|
pub mod pool;
|
||||||
pub mod one_v_one_board;
|
pub mod table_tennis;
|
||||||
pub mod overall_board;
|
pub mod user;
|
||||||
|
|
||||||
#[cfg(client)]
|
#[cfg(client)]
|
||||||
use perseus::utils::get_path_prefix_client;
|
use perseus::utils::get_path_prefix_client;
|
||||||
|
|
||||||
#[cfg(client)]
|
#[cfg(client)]
|
||||||
pub fn get_api_path(path: &str) -> String {
|
pub fn get_api_path(path: &str) -> String {
|
||||||
|
#[cfg(engine)]
|
||||||
|
{
|
||||||
|
path.to_string()
|
||||||
|
}
|
||||||
|
#[cfg(client)]
|
||||||
|
{
|
||||||
let origin = web_sys::window().unwrap().origin();
|
let origin = web_sys::window().unwrap().origin();
|
||||||
let base_path = get_path_prefix_client();
|
let base_path = get_path_prefix_client();
|
||||||
format!("{}{}{}", origin, base_path, path)
|
format!("{}{}{}", origin, base_path, path)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
0
src/templates/pickleball/mod.rs
Normal file
0
src/templates/pickleball/mod.rs
Normal file
4
src/templates/pool/mod.rs
Normal file
4
src/templates/pool/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod add_game_form;
|
||||||
|
pub mod index;
|
||||||
|
pub mod one_v_one_board;
|
||||||
|
pub mod overall_board;
|
||||||
0
src/templates/table_tennis/mod.rs
Normal file
0
src/templates/table_tennis/mod.rs
Normal file
0
src/templates/user/mod.rs
Normal file
0
src/templates/user/mod.rs
Normal file
Reference in New Issue
Block a user