new_plate_dialog callbacks
Gitea Scan/plate-tool/pipeline/head There was a failure building this commit
Details
Gitea Scan/plate-tool/pipeline/head There was a failure building this commit
Details
For #2
This commit is contained in:
parent
c2a3f0302b
commit
53457a3e86
|
@ -1 +1,2 @@
|
|||
pub mod main_window_callbacks;
|
||||
pub mod new_plate_dialog_callbacks;
|
||||
|
|
|
@ -8,6 +8,8 @@ use crate::components::states::MainState;
|
|||
use crate::data::plate::*;
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
|
||||
use crate::components::callbacks::new_plate_dialog_callbacks;
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct NewPlateDialogProps {
|
||||
pub close_callback: Callback<()>,
|
||||
|
@ -19,57 +21,12 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
|
|||
|
||||
let new_plate_callback = {
|
||||
let close_callback = props.close_callback.clone();
|
||||
Callback::from(move |e: SubmitEvent| {
|
||||
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,
|
||||
))
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
new_plate_dialog_callbacks::new_plate_callback(dispatch, close_callback)
|
||||
};
|
||||
|
||||
let onclose = {
|
||||
let close_callback = props.close_callback.clone();
|
||||
Callback::from(move |_: Event| {
|
||||
close_callback.emit(());
|
||||
})
|
||||
new_plate_dialog_callbacks::onclose(close_callback)
|
||||
};
|
||||
|
||||
// This whole section is optional, only if you want the backdrop
|
||||
|
|
Loading…
Reference in New Issue