Also integrated entities into codebase
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::data::pool_match::MatchType;
|
||||
use crate::{components::layout::Layout, data::pool_match::MatchData};
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
@@ -7,7 +6,6 @@ use web_sys::Event;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::data::pool_match::{PoolMatch, PoolMatchList, UserList};
|
||||
use crate::templates::global_state::AppStateRx;
|
||||
use crate::endpoints::{MATCH, USER};
|
||||
use crate::templates::get_api_path;
|
||||
@@ -29,28 +27,7 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
|
||||
#[cfg(client)]
|
||||
{
|
||||
// state.winner.get().as_ref().clone()
|
||||
spawn_local_scoped(cx, async move {
|
||||
let new_match = PoolMatch::new(
|
||||
MatchData {
|
||||
type_: MatchType::Standard8Ball,
|
||||
winners: vec![1],
|
||||
losers: vec![2, 3, 4],
|
||||
},
|
||||
Utc::now(),
|
||||
);
|
||||
let client = reqwest::Client::new();
|
||||
let new_matches = client
|
||||
.post(get_api_path(MATCH).as_str())
|
||||
.json(&new_match)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json::<PoolMatchList>()
|
||||
.await
|
||||
.unwrap();
|
||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||
global_state.matches.set(new_matches);
|
||||
})
|
||||
spawn_local_scoped(cx, async move {})
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,20 +35,7 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
|
||||
#[cfg(client)]
|
||||
{
|
||||
// state.winner.get().as_ref().clone()
|
||||
spawn_local_scoped(cx, async move {
|
||||
let client = reqwest::Client::new();
|
||||
let new_users = client
|
||||
.post(get_api_path(USER).as_str())
|
||||
.body(state.new_user.get().as_ref().clone())
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json::<UserList>()
|
||||
.await
|
||||
.unwrap();
|
||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||
global_state.users.set(new_users);
|
||||
})
|
||||
spawn_local_scoped(cx, async move {})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
// Not a page, global state that is shared between all pages
|
||||
|
||||
use crate::data::pool_match::PoolMatchList;
|
||||
use crate::data::pool_match::UserList;
|
||||
|
||||
use perseus::{prelude::*, state::GlobalStateCreator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -10,16 +7,12 @@ cfg_if::cfg_if! {
|
||||
if #[cfg(engine)] {
|
||||
use std::thread;
|
||||
use std::ops::Deref;
|
||||
use crate::data::store::DATA;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||
#[rx(alias = "AppStateRx")]
|
||||
pub struct AppState {
|
||||
pub matches: PoolMatchList,
|
||||
pub users: UserList,
|
||||
}
|
||||
pub struct AppState {}
|
||||
|
||||
pub fn get_global_state_creator() -> GlobalStateCreator {
|
||||
GlobalStateCreator::new()
|
||||
@@ -29,15 +22,7 @@ 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 users = thread::spawn(move || DATA.lock().unwrap().deref().users.clone())
|
||||
.join()
|
||||
.unwrap();
|
||||
|
||||
AppState { matches, users }
|
||||
AppState {}
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
use crate::{components::layout::Layout, templates::global_state::AppStateRx, data::user::PlayerId};
|
||||
use crate::{components::layout::Layout, templates::global_state::AppStateRx};
|
||||
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
|
||||
use crate::data::pool_match::PoolMatch;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "PageStateRx")]
|
||||
struct PageState {}
|
||||
|
||||
fn format_list_or_single(to_format: &Vec<PlayerId>) -> String{
|
||||
match to_format.len() {
|
||||
1 => to_format[0].to_string(),
|
||||
_ => format!("{:?}", to_format),
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -24,24 +15,7 @@ fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageSta
|
||||
Layout(title = "Overall Leaderboard") {
|
||||
ul {
|
||||
(View::new_fragment(
|
||||
global_state.matches.get()
|
||||
.pool_matches
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|item: &PoolMatch| {
|
||||
let game = item.clone();
|
||||
|
||||
view! { cx,
|
||||
li (class = "text-blue-700", id = "ha",) {
|
||||
(game.id)
|
||||
(" ")
|
||||
(format_list_or_single(&game.data.winners))
|
||||
(" ")
|
||||
(format_list_or_single(&game.data.losers))
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
vec![],
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user