From cd8b52cd29a9ac32b904f0d91cbef1ec07cc0df5 Mon Sep 17 00:00:00 2001 From: Matthew Kaminski Date: Sun, 29 Oct 2023 23:30:38 -0400 Subject: [PATCH] Co-authored-by: jkassman --- src/data/pool_match.rs | 25 ++++++++++++------------- src/templates/add_game_form.rs | 10 +++++++++- src/templates/overall_board.rs | 21 +++++++++++++++++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/data/pool_match.rs b/src/data/pool_match.rs index 3ddf92d..3ee5b55 100644 --- a/src/data/pool_match.rs +++ b/src/data/pool_match.rs @@ -6,19 +6,17 @@ use serde::{Deserialize, Serialize}; pub type MatchId = u32; #[derive(Serialize, Deserialize, Clone, Debug)] -pub enum MatchData { - Standard8Ball { - winner: PlayerId, - loser: PlayerId, - }, - Standard9Ball { - winner: PlayerId, - loser: PlayerId, - }, - CutThroat { - winner: PlayerId, - losers: [PlayerId; 2], - }, +pub enum MatchType { + Standard8Ball, + Standard9Ball, + CutThroat, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct MatchData { + pub type_: MatchType, + pub winners: Vec, + pub losers: Vec, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -28,6 +26,7 @@ pub struct PoolMatch { #[serde(with = "ts_seconds")] pub time: DateTime, } + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct PoolMatchList { pub pool_matches: Vec, diff --git a/src/templates/add_game_form.rs b/src/templates/add_game_form.rs index 285b9a9..0939d14 100644 --- a/src/templates/add_game_form.rs +++ b/src/templates/add_game_form.rs @@ -1,3 +1,4 @@ +use crate::data::pool_match::MatchType; use crate::{components::layout::Layout, data::pool_match::MatchData}; use perseus::prelude::*; 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() 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 new_matches = client .post(get_api_path(MATCH).as_str()) diff --git a/src/templates/overall_board.rs b/src/templates/overall_board.rs index cd86580..5bc0f26 100644 --- a/src/templates/overall_board.rs +++ b/src/templates/overall_board.rs @@ -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 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) -> 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 { let global_state = Reactor::::from_cx(cx).get_global_state::(cx); @@ -19,12 +28,16 @@ fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageSta .pool_matches .iter() .rev() - .enumerate() - .map(|(_index, item)| { + .map(|item: &PoolMatch| { let game = item.clone(); + view! { cx, - li { + li (class = "text-blue-700", id = "ha",) { (game.id) + (" ") + (format_list_or_single(&game.data.winners)) + (" ") + (format_list_or_single(&game.data.losers)) } } })