2 Commits

Author SHA1 Message Date
cb5da9b966 Merge pull request 'Refactor PoolMatch' (#5) from refactor-pool-match into main
All checks were successful
Build Crate / build (push) Successful in 9m6s
Reviewed-on: https://questia.dev/git/vsquad/pool-elo/pulls/5
Reviewed-by: Matthew Kaminski <kaminskimateusz7@gmail.com>
2023-12-10 00:09:49 +00:00
cd8b52cd29 Co-authored-by: jkassman <jkassman@users.noreply.github.com>
All checks were successful
Build Crate / build (push) Successful in 8m23s
2023-10-29 23:30:38 -04:00
3 changed files with 38 additions and 18 deletions

View File

@@ -6,19 +6,17 @@ use serde::{Deserialize, Serialize};
pub type MatchId = u32; pub type MatchId = u32;
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub enum MatchData { pub enum MatchType {
Standard8Ball { Standard8Ball,
winner: PlayerId, Standard9Ball,
loser: PlayerId, CutThroat,
}, }
Standard9Ball {
winner: PlayerId, #[derive(Serialize, Deserialize, Clone, Debug)]
loser: PlayerId, pub struct MatchData {
}, pub type_: MatchType,
CutThroat { pub winners: Vec<PlayerId>,
winner: PlayerId, pub losers: Vec<PlayerId>,
losers: [PlayerId; 2],
},
} }
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
@@ -28,6 +26,7 @@ pub struct PoolMatch {
#[serde(with = "ts_seconds")] #[serde(with = "ts_seconds")]
pub time: DateTime<Utc>, pub time: DateTime<Utc>,
} }
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct PoolMatchList { pub struct PoolMatchList {
pub pool_matches: Vec<PoolMatch>, pub pool_matches: Vec<PoolMatch>,

View File

@@ -1,3 +1,4 @@
use crate::data::pool_match::MatchType;
use crate::{components::layout::Layout, data::pool_match::MatchData}; use crate::{components::layout::Layout, data::pool_match::MatchData};
use perseus::prelude::*; use perseus::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -28,7 +29,14 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
{ {
// state.name.get().as_ref().clone() // state.name.get().as_ref().clone()
spawn_local_scoped(cx, async move { spawn_local_scoped(cx, async move {
let new_match = PoolMatch::new(MatchData::Standard8Ball { winner: 1, loser: 2 }, Utc::now()); 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 client = reqwest::Client::new();
let new_matches = client let new_matches = client
.post(get_api_path(MATCH).as_str()) .post(get_api_path(MATCH).as_str())

View File

@@ -1,13 +1,22 @@
use crate::{components::layout::Layout, templates::global_state::AppStateRx}; use crate::{components::layout::Layout, templates::global_state::AppStateRx, data::user::PlayerId};
use perseus::prelude::*; use perseus::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sycamore::prelude::*; use sycamore::prelude::*;
use crate::data::pool_match::PoolMatch;
#[derive(Serialize, Deserialize, Clone, ReactiveState)] #[derive(Serialize, Deserialize, Clone, ReactiveState)]
#[rx(alias = "PageStateRx")] #[rx(alias = "PageStateRx")]
struct PageState {} 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> { 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); let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
@@ -19,12 +28,16 @@ fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageSta
.pool_matches .pool_matches
.iter() .iter()
.rev() .rev()
.enumerate() .map(|item: &PoolMatch| {
.map(|(_index, item)| {
let game = item.clone(); let game = item.clone();
view! { cx, view! { cx,
li { li (class = "text-blue-700", id = "ha",) {
(game.id) (game.id)
(" ")
(format_list_or_single(&game.data.winners))
(" ")
(format_list_or_single(&game.data.losers))
} }
} }
}) })