Fix more clippy issues, implement forgot password
All checks were successful
Build Crate / build (push) Successful in 1m48s
All checks were successful
Build Crate / build (push) Successful in 1m48s
This commit is contained in:
@@ -4,14 +4,6 @@ use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use web_sys::Event;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::global_state::AppStateRx;
|
||||
use crate::templates::get_api_path;
|
||||
use chrono::Utc;
|
||||
}
|
||||
}
|
||||
|
||||
// Reactive page
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
@@ -39,7 +31,7 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
|
||||
};
|
||||
|
||||
view! { cx,
|
||||
Layout(title = "Add Game Results", game = GameState::Pool) {
|
||||
Layout(game = GameState::Pool) {
|
||||
div (class = "flex flex-wrap") {
|
||||
select {
|
||||
option (value="red")
|
||||
|
||||
66
src/templates/global_state.rs
Normal file
66
src/templates/global_state.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use sycamore::prelude::*;
|
||||
|
||||
fn index_page<G: Html>(cx: Scope) -> View<G> {
|
||||
view! { cx,
|
||||
Layout(title = "Index", game = GameState::Pool) {
|
||||
Layout(game = GameState::Pool) {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
p { "Hello World!" }
|
||||
br {}
|
||||
|
||||
@@ -9,7 +9,7 @@ struct PageState {}
|
||||
|
||||
fn one_v_one_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageStateRx) -> View<G> {
|
||||
view! { cx,
|
||||
Layout(title = "1v1 Leaderboard", game = GameState::Pool) {
|
||||
Layout(game = GameState::Pool) {
|
||||
p { "leaderboard" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageSta
|
||||
let _global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||
|
||||
view! { cx,
|
||||
Layout(title = "Overall Leaderboard", game = GameState::Pool) {
|
||||
Layout(game = GameState::Pool) {
|
||||
ul {
|
||||
(View::new_fragment(
|
||||
vec![],
|
||||
|
||||
Reference in New Issue
Block a user