diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-09-05 14:04:02 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-09-05 14:04:16 -0400 |
commit | 5391187338b6f3dafe840ecc92fa91bd82f5c670 (patch) | |
tree | 98b8b8a10b82fea9ef73b33d3b5555ada3809e8f /webapp/src/main.rs | |
parent | 19564fd7385266d6628376e743884e65e5a645e1 (diff) |
Add bidding box component
Diffstat (limited to 'webapp/src/main.rs')
-rw-r--r-- | webapp/src/main.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/webapp/src/main.rs b/webapp/src/main.rs index 4e61344..61e007c 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -2,8 +2,9 @@ use crate::card::{Rank, Suit}; #[allow(unused_imports)] use log::{debug, error, info, warn}; use yew::prelude::*; -pub mod card; pub mod bridge_engine; +pub mod card; +use bridge_engine::Bid; extern crate wee_alloc; // Use `wee_alloc` as the global allocator. @@ -44,6 +45,8 @@ pub fn app() -> Html { html! { <> + <p>{ "Bids" }</p> + <BiddingBox lower_limit={"1H".parse::<Bid>().unwrap()} /> <p>{ "North" }</p> <Hand ..(*north).clone() /> <p>{ "West" }</p> @@ -125,6 +128,46 @@ impl From<card::Card> for CardProps { } } +pub fn bid_css_class(suit: Option<Suit>) -> &'static str { + match suit { + None => "suit-notrump", + Some(x) => suit_css_class(x), + } +} + +#[function_component(BiddingBox)] +pub fn bidding_box(props: &BiddingBoxProps) -> Html { + let bids: Html = Bid::all_bids() + .iter() + .map(|bid| { + let mut class = if bid < &props.lower_limit { + classes!("disabled") + } else { + classes!("enabled") + }; + class.extend( + classes!(bid_css_class(bid.suit))); + html! { + <div class={class}> + { bid.level } + </div> + } + }) + .collect(); + + html! { + <div class="bidding-box"> + { bids } + </div> + } +} + +#[derive(PartialEq, Properties, Clone)] +pub struct BiddingBoxProps { + #[prop_or("1♣".parse().unwrap())] + lower_limit: Bid, +} + #[cfg(test)] mod tests { pub fn test_setup() { |