use crate::card::{Rank, Suit}; #[allow(unused_imports)] use log::{debug, error, info, warn}; use yew::prelude::*; pub mod card; pub mod bridge_engine; extern crate wee_alloc; // Use `wee_alloc` as the global allocator. #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; fn main() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); wasm_logger::init(wasm_logger::Config::default()); yew::start_app::(); } #[function_component(App)] pub fn app() -> Html { let mut rng = rand::thread_rng(); let (n, w, s, e) = card::shuffle_deck(&mut rng); let north = use_state(|| HandProps::from_iter(n.into_iter())); let west = use_state(|| HandProps::from_iter(w.into_iter())); let south = use_state(|| HandProps::from_iter(s.into_iter())); let east = use_state(|| HandProps::from_iter(e.into_iter())); let shuffle = { let north = north.clone(); let west = west.clone(); let south = south.clone(); let east = east.clone(); Callback::from(move |_| { let mut rng = rand::thread_rng(); let (n, w, s, e) = card::shuffle_deck(&mut rng); north.set(n.into_iter().collect()); west.set(w.into_iter().collect()); south.set(s.into_iter().collect()); east.set(e.into_iter().collect()); }) }; html! { <>

{ "North" }

{ "West" }

{ "South" }

{ "East" }

} } #[function_component(Hand)] pub fn hand(props: &HandProps) -> Html { let cards: Html = props .cards .iter() .map(|c| { html! { } }) .collect(); html! {
{ cards }
} } pub fn suit_css_class(suit: Suit) -> &'static str { match suit { Suit::Club => "suit-club", Suit::Diamond => "suit-diamond", Suit::Heart => "suit-heart", Suit::Spade => "suit-spade", } } #[derive(Clone, Default, PartialEq, Properties)] pub struct HandProps { #[prop_or_default] cards: Vec, } impl> FromIterator for HandProps { fn from_iter(cards: Cards) -> Self where Cards: std::iter::IntoIterator, { HandProps { cards: cards.into_iter().map(Into::into).collect(), } } } #[function_component(Card)] pub fn wcard(props: &CardProps) -> Html { html! {
{ props.rank }
} } #[derive(PartialEq, Properties, Clone)] pub struct CardProps { suit: Suit, rank: Rank, } impl From for CardProps { fn from(card::Card(suit, rank): card::Card) -> Self { CardProps { suit, rank } } } #[cfg(test)] mod tests { pub fn test_setup() { dotenv::dotenv().ok(); let _ = env_logger::builder().is_test(true).try_init(); } }