Compare commits
4 Commits
add_api
...
refactor-p
| Author | SHA1 | Date | |
|---|---|---|---|
| cd8b52cd29 | |||
| 319c77cfa3 | |||
| ae4cb23acb | |||
| f31e87780f |
@@ -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<PlayerId>,
|
||||
pub losers: Vec<PlayerId>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
@@ -28,6 +26,7 @@ pub struct PoolMatch {
|
||||
#[serde(with = "ts_seconds")]
|
||||
pub time: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PoolMatchList {
|
||||
pub pool_matches: Vec<PoolMatch>,
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user