From 5391187338b6f3dafe840ecc92fa91bd82f5c670 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Mon, 5 Sep 2022 14:04:02 -0400 Subject: Add bidding box component --- webapp/src/main.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'webapp/src/main.rs') 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! { <> +

{ "Bids" }

+ ().unwrap()} />

{ "North" }

{ "West" }

@@ -125,6 +128,46 @@ impl From for CardProps { } } +pub fn bid_css_class(suit: Option) -> &'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! { +
+ { bid.level } +
+ } + }) + .collect(); + + html! { +
+ { bids } +
+ } +} + +#[derive(PartialEq, Properties, Clone)] +pub struct BiddingBoxProps { + #[prop_or("1♣".parse().unwrap())] + lower_limit: Bid, +} + #[cfg(test)] mod tests { pub fn test_setup() { -- cgit v1.2.3