summaryrefslogtreecommitdiff
path: root/webapp
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-12-22 14:50:28 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-12-22 14:50:28 -0500
commit147f3bcbcd18ff5afd57c92cbb0b58eed4d68595 (patch)
treef5d4851c6fa334aa7a685977e69088349c535a37 /webapp
parentcca246746538a5e689168741b2e9e2542613cf8a (diff)
Simplify table component with updated table state representation
Diffstat (limited to 'webapp')
-rw-r--r--webapp/src/components/table.rs57
1 files changed, 20 insertions, 37 deletions
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! { <p>{"Loading table"}</p> },
+ };
+
html! {
<>
- <p>{ format!("This is table {}", props.table.id) }</p>
+ p<>{ format!("This is table {}", props.table.id) }</p>
<button onclick={leave_table}>
{ "Leave table" }
</button>
- if let Some(table_state) = &*table_state {
- <Table table={ table_state.clone() } { on_bid } />
- }
+ { 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! {
- <>
- <BiddingTable bidding={bidding.clone()} />
- <BiddingBox current_bid={bidding.highest_bid().clone()} on_bid={ props.on_bid.clone() } />
- { 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<Bid>,
+) -> Html {
html! {
<>
<div class="center">
- { center }
+ <BiddingTable bidding={bidding.bidding.clone()} />
+ <BiddingBox current_bid={bidding.bidding.highest_bid().clone()} on_bid={ on_bid } />
+ { format!("It is {:?} to bid", bidding.bidding.current_bidder()) }
</div>
<div class="hand south">
- <Hand cards={ props.table.hand().clone() } on_card_clicked={ on_card_clicked.clone() } />
+ <Hand cards={ bidding.hand.clone() } on_card_clicked={ Callback::from(|card| {}) } />
</div>
<h2>{ "Table view" }</h2>
- <pre>{ format!("{:#?}", props.table) }</pre>
+ <pre>{ format!("{:#?}", bidding) }</pre>
</>
}
}
-
-#[derive(PartialEq, Properties, Clone)]
-pub struct TableProps {
- pub table: GameStatePlayerView,
- pub on_bid: Callback<Bid>,
-}