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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use futuresdr_types::Pmt;
use futuresdr_types::PortId;
use indexmap::IndexMap;
use leptos::logging::*;
use leptos::prelude::*;
use leptos::task::spawn_local;
use uuid::Uuid;
use crate::FlowgraphHandle;
#[component]
/// Radio Selector
///
/// Selecting an entry triggers sending a PMT.
pub fn RadioSelector<P: Into<PortId>, V: IntoIterator<Item = (String, Pmt)>>(
fg_handle: FlowgraphHandle,
block_id: usize,
handler: P,
values: V,
#[prop(into, optional)] label_class: String,
) -> impl IntoView {
let handler = handler.into();
let uuid = Uuid::new_v4();
let values: IndexMap<String, Pmt> = IndexMap::from_iter(values);
view! {
<div>
{values
.into_iter()
.map(|(n, p)| {
let fg_handle = fg_handle.clone();
let handler = handler.clone();
let label_class = label_class.clone();
let id = Uuid::new_v4();
view! {
<input
type="radio"
id=id.to_string()
name=uuid.to_string()
on:change=move |_| {
let p = p.clone();
let fg_handle = fg_handle.clone();
let handler = handler.clone();
spawn_local(async move {
log!(
"sending block {} handler {:?} pmt {:?}",
block_id,
&handler,
&p
);
let _ = fg_handle.post(block_id, handler, p).await;
});
}
/>
<label class=label_class for=id.to_string()>
{n}
</label>
}
})
.collect::<Vec<_>>()}
</div>
}
}