blob: b8fd8931c60899ef38494f2338ee46f6c32c4891 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
use crate::bridge_engine::{Bid, BiddingResult, Player};
use crate::components::{BiddingBox, BiddingTable};
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)) } />
</>
}
}
}
|