2024-09-13 07:07:49 +00:00
|
|
|
use itertools::Itertools;
|
2024-09-12 22:24:41 +00:00
|
|
|
use sycamore::{prelude::*, web::tags::div};
|
|
|
|
|
2024-09-13 22:15:55 +00:00
|
|
|
use crate::AppState;
|
2024-09-12 22:24:41 +00:00
|
|
|
|
|
|
|
#[component]
|
2024-09-13 22:15:55 +00:00
|
|
|
pub fn Outline() -> View {
|
|
|
|
let state = use_context::<AppState>();
|
2024-09-12 22:24:41 +00:00
|
|
|
|
2024-09-13 07:07:49 +00:00
|
|
|
// sort the elements alphabetically by ID
|
|
|
|
let elements_sorted = create_memo(move ||
|
2024-09-13 07:40:34 +00:00
|
|
|
state.assembly.elements
|
2024-09-13 07:07:49 +00:00
|
|
|
.get_clone()
|
|
|
|
.into_iter()
|
|
|
|
.sorted_by_key(|elt| elt.id.clone())
|
|
|
|
.collect()
|
|
|
|
);
|
|
|
|
|
2024-09-12 22:24:41 +00:00
|
|
|
view! {
|
|
|
|
ul {
|
|
|
|
Keyed(
|
2024-09-13 07:07:49 +00:00
|
|
|
list=elements_sorted,
|
2024-09-12 22:24:41 +00:00
|
|
|
view=|elt| {
|
2024-09-13 05:36:54 +00:00
|
|
|
let label = elt.label.clone();
|
2024-09-13 07:43:19 +00:00
|
|
|
let rep_components = elt.rep.iter().map(|u| {
|
|
|
|
let u_coord = u.to_string().replace("-", "\u{2212}");
|
|
|
|
View::from(div().children(u_coord))
|
|
|
|
}).collect::<Vec<_>>();
|
2024-09-12 22:24:41 +00:00
|
|
|
view! {
|
2024-09-13 21:53:12 +00:00
|
|
|
/* [TO DO] switch to integer-valued parameters whenever
|
|
|
|
that becomes possible again */
|
|
|
|
li(tabindex="0") {
|
2024-09-13 05:36:54 +00:00
|
|
|
div(class="elt-label") { (label) }
|
2024-09-12 22:24:41 +00:00
|
|
|
div(class="elt-rep") { (rep_components) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-09-13 05:36:54 +00:00
|
|
|
key=|elt| elt.id.clone()
|
2024-09-12 22:24:41 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|