summaryrefslogtreecommitdiff
path: root/webapp/src/components/bidding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/components/bidding.rs')
-rw-r--r--webapp/src/components/bidding.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/webapp/src/components/bidding.rs b/webapp/src/components/bidding.rs
new file mode 100644
index 0000000..50ff72f
--- /dev/null
+++ b/webapp/src/components/bidding.rs
@@ -0,0 +1,51 @@
+use crate::bridge_engine::{self, Bid, BiddingResult, Player};
+use crate::components::{BiddingBox, BiddingTable};
+use log::info;
+use yew::prelude::*;
+
+#[derive(Debug)]
+pub enum Msg {
+ Bid(Bid),
+}
+
+pub struct Bidding {
+ bidding: BiddingResult,
+}
+
+#[derive(PartialEq, Properties)]
+pub struct BiddingProperties {
+ pub dealer: Player,
+}
+
+impl Component for Bidding {
+ type Message = Msg;
+ type Properties = BiddingProperties;
+
+ fn create(ctx: &Context<Self>) -> Self {
+ Self {
+ bidding: BiddingResult::new(ctx.props().dealer),
+ }
+ }
+
+ fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
+ match msg {
+ Msg::Bid(bid) => {
+ self.bidding = self.bidding.bidding().clone().bid(bid).unwrap();
+ true
+ }
+ }
+ }
+
+ fn view(&self, ctx: &Context<Self>) -> Html {
+ html! {
+ <>
+ <p>{ "Bidding table" }</p>
+ <BiddingTable bidding={ self.bidding.bidding().clone() } />
+ <p>{ "Bidding box" }</p>
+ <BiddingBox
+ current_bid={ self.bidding.bidding().highest_bid().clone() }
+ on_bid={ ctx.link().callback(|bid| Msg::Bid(bid)) } />
+ </>
+ }
+ }
+}