summaryrefslogtreecommitdiff
path: root/webapp/src/components/hand.rs
blob: 85b4dd265c872233cf36713eccb7f2b007887ff1 (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
use yew::prelude::*;
use crate::components::card::{Card, CardProps};

#[function_component(Hand)]
pub fn hand(props: &HandProps) -> Html {
    let cards = props
        .cards
        .iter()
        .map(|c| {
            html! {
                <Card ..c.clone() />
            }
        });

    html! {
        { for cards }
    }
}

#[derive(Clone, Default, PartialEq, Properties)]
pub struct HandProps {
    #[prop_or_default]
    cards: Vec<CardProps>,
}

impl<C: Into<CardProps>> FromIterator<C> for HandProps {
    fn from_iter<Cards>(cards: Cards) -> Self
    where
        Cards: std::iter::IntoIterator<Item = C>,
    {
        HandProps {
            cards: cards.into_iter().map(Into::into).collect(),
        }
    }
}