Store a product regulator's subjects in an array

This lets us iterate over subjects. Based on commit 257ce33, with a few
updates from 4a9e777.
This commit is contained in:
Aaron Fenyes 2025-03-26 23:50:40 -07:00
parent 7c40d60103
commit 00f60b0e90
3 changed files with 35 additions and 38 deletions

View file

@ -188,11 +188,16 @@ pub fn AddRemove() -> View {
},
on:click=|_| {
let state = use_context::<AppState>();
let subjects = state.selection.with(
|sel| {
let subject_vec: Vec<_> = sel.into_iter().collect();
(subject_vec[0].clone(), subject_vec[1].clone())
}
let subjects: [_; 2] = state.selection.with(
// the button is only enabled when two elements are
// selected, so we know the cast to a two-element array
// will succeed
|sel| sel
.clone()
.into_iter()
.collect::<Vec<_>>()
.try_into()
.unwrap()
);
state.assembly.insert_new_regulator(subjects);
state.selection.update(|sel| sel.clear());