use crate::components::{BiddingBox, BiddingTable}; use log::error; use protocol::{bridge_engine::{self, BiddingResult}, core::Player, contract::Contract}; use yew::prelude::*; #[derive(PartialEq, Properties, Clone)] pub struct BiddingProperties { pub dealer: Player, pub on_contract: Callback<(Option, bridge_engine::Bidding)>, } #[function_component(Bidding)] pub fn bidding(props: &BiddingProperties) -> Html { let bidding = use_state(|| bridge_engine::Bidding::new(props.dealer)); { let bidding = bidding.clone(); let dealer = props.dealer; use_effect_with_deps( move |_| { bidding.set(bridge_engine::Bidding::new(dealer)); || () }, dealer, ); } let on_bid = { let bidding = bidding.clone(); let on_contract = props.on_contract.clone(); Callback::from(move |bid| match (*bidding).clone().bid(bid) { Ok(BiddingResult::Contract(contract, bidding)) => { on_contract.emit((contract, bidding)); } Ok(BiddingResult::InProgress(new_bidding)) => { bidding.set(new_bidding); } Err(err) => { error!("Failed to place bid: {:?}", err); } }) }; html! { <>

{ "Bidding box" }

{ "Bidding table" }

} }