new_plate_dialog callbacks
Gitea Scan/plate-tool/pipeline/head There was a failure building this commit Details

For #2
This commit is contained in:
Emilia Allison 2024-01-13 14:05:34 -05:00
parent c2a3f0302b
commit 53457a3e86
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
2 changed files with 5 additions and 47 deletions

View File

@ -1 +1,2 @@
pub mod main_window_callbacks; pub mod main_window_callbacks;
pub mod new_plate_dialog_callbacks;

View File

@ -8,6 +8,8 @@ use crate::components::states::MainState;
use crate::data::plate::*; use crate::data::plate::*;
use crate::data::plate_instances::PlateInstance; use crate::data::plate_instances::PlateInstance;
use crate::components::callbacks::new_plate_dialog_callbacks;
#[derive(PartialEq, Properties)] #[derive(PartialEq, Properties)]
pub struct NewPlateDialogProps { pub struct NewPlateDialogProps {
pub close_callback: Callback<()>, pub close_callback: Callback<()>,
@ -19,57 +21,12 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
let new_plate_callback = { let new_plate_callback = {
let close_callback = props.close_callback.clone(); let close_callback = props.close_callback.clone();
Callback::from(move |e: SubmitEvent| { new_plate_dialog_callbacks::new_plate_callback(dispatch, close_callback)
e.prevent_default();
close_callback.emit(());
let target: Option<EventTarget> = e.target();
let form = target.and_then(|t| t.dyn_into::<HtmlFormElement>().ok());
if let Some(form) = form {
if let Ok(form_data) = FormData::new_with_form(&form) {
let name = form_data.get("new_plate_name").as_string().unwrap();
let format = match form_data.get("plate_format").as_string().unwrap().as_str() {
"6" => PlateFormat::W6,
"12" => PlateFormat::W12,
"24" => PlateFormat::W24,
"48" => PlateFormat::W48,
"96" => PlateFormat::W96,
"384" => PlateFormat::W384,
"1536" => PlateFormat::W1536,
"3456" => PlateFormat::W3456,
_ => unreachable!(),
};
if let Some(pt_string) = form_data.get("new_plate_type").as_string() {
let plate_type = match pt_string.as_str() {
"src" => PlateType::Source,
"dest" => PlateType::Destination,
_ => PlateType::Source,
};
dispatch.reduce_mut(|s| {
if plate_type == PlateType::Source {
s.add_source_plate(PlateInstance::new(
PlateType::Source,
format,
name,
))
} else {
s.add_dest_plate(PlateInstance::new(
PlateType::Destination,
format,
name,
))
}
});
}
}
}
})
}; };
let onclose = { let onclose = {
let close_callback = props.close_callback.clone(); let close_callback = props.close_callback.clone();
Callback::from(move |_: Event| { new_plate_dialog_callbacks::onclose(close_callback)
close_callback.emit(());
})
}; };
// This whole section is optional, only if you want the backdrop // This whole section is optional, only if you want the backdrop