summaryrefslogtreecommitdiff
path: root/webapp/src/components/trick_in_play.rs
blob: e5790a3348906ce4b97ef52bd41ab472df469d55 (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
use crate::components::Card;
use protocol::{bridge_engine::Trick, core::Player};
use yew::prelude::*;

#[function_component(TrickInPlay)]
pub fn trick_in_play(props: &TrickInPlayProps) -> Html {
    let leader = props.trick.leader;
    let cards = props
        .trick
        .cards_played
        .iter()
        .enumerate()
        .map(|(i, card)| {
            // TODO: Support other player positions.
            let class = match leader.many_next(i) {
                Player::West => classes!("left"),
                Player::North => classes!("top"),
                Player::East => classes!("right"),
                Player::South => classes!("bottom"),
            };
            html! {
                <div class={class}>
                  <Card card={*card} />
                </div>
            }
        });
    html! {
        <>
            <div class="trick-layout">
              { for cards }
            </div>
        </>
    }
}

#[derive(PartialEq, Properties, Clone)]
pub struct TrickInPlayProps {
    pub trick: Trick,
}