Add base data structures for pool matches
Some checks failed
Build Crate / build (push) Failing after 4m29s

This commit is contained in:
2023-09-22 03:45:48 -04:00
parent 0a68829d6c
commit 30f3aa63d5
16 changed files with 148 additions and 123 deletions

View File

@@ -1,8 +1,8 @@
use crate::components::layout::Layout;
use crate::{components::layout::Layout, data::pool_match::MatchData};
use perseus::prelude::*;
use serde::{Deserialize, Serialize};
use sycamore::prelude::*;
use web_sys::{Event};
use web_sys::Event;
cfg_if::cfg_if! {
if #[cfg(client)] {
@@ -10,10 +10,10 @@ cfg_if::cfg_if! {
use crate::templates::global_state::AppStateRx;
use crate::endpoints::MATCH;
use crate::templates::get_api_path;
use chrono::Utc;
}
}
// Reactive page
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
@@ -22,20 +22,16 @@ struct PageState {
name: String,
}
fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
let handle_add_match = move |_event: Event| {
#[cfg(client)]
{
// state.name.get().as_ref().clone()
spawn_local_scoped(cx, async move {
let new_match = PoolMatch {
players: vec![],
winner: state.name.get().as_ref().clone(),
};
let new_match = PoolMatch::new(MatchData::Standard8Ball { winner: 1, loser: 2 }, Utc::now());
let client = reqwest::Client::new();
let new_matches = client.post(get_api_path(MATCH).as_str())
let new_matches = client
.post(get_api_path(MATCH).as_str())
.json(&new_match)
.send()
.await
@@ -45,7 +41,6 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
.unwrap();
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
global_state.matches.set(new_matches);
})
}
};
@@ -75,7 +70,9 @@ async fn get_request_state(
_info: StateGeneratorInfo<()>,
_req: Request,
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
Ok(PageState { name: "Ferris".to_string() })
Ok(PageState {
name: "Ferris".to_string(),
})
}
#[engine_only_fn]

View File

@@ -1,3 +1,6 @@
// Not a page, global state that is shared between all pages
use crate::data::pool_match::PoolMatchList;
use perseus::{prelude::*, state::GlobalStateCreator};
use serde::{Deserialize, Serialize};
@@ -5,13 +8,10 @@ cfg_if::cfg_if! {
if #[cfg(engine)] {
use std::thread;
use std::ops::Deref;
use crate::data::store::DATA;
}
}
#[cfg(engine)]
use crate::data::store::DATA;
use crate::data::pool_match::PoolMatchList;
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
#[rx(alias = "AppStateRx")]
pub struct AppState {
@@ -26,16 +26,13 @@ pub fn get_global_state_creator() -> GlobalStateCreator {
#[engine_only_fn]
fn get_state() -> AppState {
let matches = thread::spawn(move || {
DATA.lock().unwrap().deref().matches.clone()
}).join().unwrap();
let matches = thread::spawn(move || DATA.lock().unwrap().deref().matches.clone())
.join()
.unwrap();
AppState {
matches
}
AppState { matches }
}
#[engine_only_fn]
pub async fn get_build_state() -> AppState {
get_state()

View File

@@ -20,8 +20,5 @@ fn head(cx: Scope) -> View<SsrNode> {
}
pub fn get_template<G: Html>() -> Template<G> {
Template::build("")
.view(index_page)
.head(head)
.build()
Template::build("").view(index_page).head(head).build()
}

View File

@@ -1,8 +1,8 @@
pub mod index;
pub mod add_game_form;
pub mod global_state;
pub mod index;
pub mod one_v_one_board;
pub mod overall_board;
pub mod global_state;
#[cfg(client)]
use perseus::utils::get_path_prefix_client;

View File

@@ -3,18 +3,13 @@ use perseus::prelude::*;
use serde::{Deserialize, Serialize};
use sycamore::prelude::*;
// Reactive page
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
#[rx(alias = "PageStateRx")]
struct PageState {
}
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") {
// Anything we put in here will be rendered inside the `<main>` block of the layout
p { "leaderboard" }
}
}
@@ -35,9 +30,6 @@ fn head(cx: Scope) -> View<SsrNode> {
}
}
// Template
pub fn get_template<G: Html>() -> Template<G> {
Template::build("one-v-one-board")
.request_state_fn(get_request_state)

View File

@@ -1,23 +1,18 @@
use crate::components::layout::Layout;
use crate::{components::layout::Layout, templates::global_state::AppStateRx};
use perseus::prelude::*;
use serde::{Deserialize, Serialize};
use sycamore::prelude::*;
use crate::templates::global_state::AppStateRx;
// Reactive page
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
#[rx(alias = "PageStateRx")]
struct PageState {
}
struct PageState {}
fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageStateRx) -> View<G> {
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
view! { cx,
Layout(title = "Overall Leaderboard") {
// Anything we put in here will be rendered inside the `<main>` block of the layout
ul {
(View::new_fragment(
global_state.matches.get()
@@ -29,7 +24,7 @@ fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageSta
let game = item.clone();
view! { cx,
li {
(game.winner)
(game.id)
}
}
})
@@ -55,9 +50,6 @@ fn head(cx: Scope) -> View<SsrNode> {
}
}
// Template
pub fn get_template<G: Html>() -> Template<G> {
Template::build("overall-board")
.request_state_fn(get_request_state)