From 147f3bcbcd18ff5afd57c92cbb0b58eed4d68595 Mon Sep 17 00:00:00 2001
From: Kjetil Orbekk
Date: Thu, 22 Dec 2022 14:50:28 -0500
Subject: Simplify table component with updated table state representation
---
webapp/src/components/table.rs | 57 +++++++++++++++---------------------------
1 file changed, 20 insertions(+), 37 deletions(-)
(limited to 'webapp/src/components')
diff --git a/webapp/src/components/table.rs b/webapp/src/components/table.rs
index 17c37b1..fa21102 100644
--- a/webapp/src/components/table.rs
+++ b/webapp/src/components/table.rs
@@ -9,6 +9,7 @@ use gloo_net::http::Request;
use log::info;
use protocol::bridge_engine::{
Bid, BiddingState, BiddingStatePlayerView, GameStatePlayerView,
+ PlayStatePlayerView,
};
use yew::prelude::*;
@@ -69,7 +70,7 @@ pub fn online_table(props: &OnlineTableProps) -> Html {
.json(&bid)?
.send()
.await
- .context("submitting bid")?;
+ .context("submitting bid")?;
let () = ok_json(bid_response).await?;
update_table_state().await?;
Ok(())
@@ -84,15 +85,20 @@ pub fn online_table(props: &OnlineTableProps) -> Html {
})
};
+ let center = match &*table_state {
+ Some(GameStatePlayerView::Bidding(bidding)) =>
+ bidding_view(bidding, on_bid),
+ Some(GameStatePlayerView::Playing(playing)) => todo!(),
+ None => html! { {"Loading table"}
},
+ };
+
html! {
<>
- { format!("This is table {}", props.table.id) }
+ p<>{ format!("This is table {}", props.table.id) }
- if let Some(table_state) = &*table_state {
-
- }
+ { center }
>
}
}
@@ -102,45 +108,22 @@ pub struct OnlineTableProps {
pub table: protocol::Table,
}
-#[function_component(Table)]
-pub fn table(props: &TableProps) -> Html {
- let on_card_clicked = {
- Callback::from(move |card| {
- info!("Card clicked: {}", card);
- })
- };
-
- let center = match &props.table {
- GameStatePlayerView::Bidding(BiddingStatePlayerView {
- bidding,
- ..
- }) => html! {
- <>
-
-
- { format!("It is {:?} to bid", bidding.current_bidder()) }
- >
- },
- GameStatePlayerView::PassedOut { .. } => todo!(),
- GameStatePlayerView::Lead { .. } => todo!(),
- GameStatePlayerView::Play { .. } => todo!(),
- };
+pub fn bidding_view(
+ bidding: &BiddingStatePlayerView,
+ on_bid: Callback,
+) -> Html {
html! {
<>
- { center }
+
+
+ { format!("It is {:?} to bid", bidding.bidding.current_bidder()) }
-
+
{ "Table view" }
- { format!("{:#?}", props.table) }
+ { format!("{:#?}", bidding) }
>
}
}
-
-#[derive(PartialEq, Properties, Clone)]
-pub struct TableProps {
- pub table: GameStatePlayerView,
- pub on_bid: Callback,
-}
--
cgit v1.2.3