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

This commit is contained in:
Emilia Allison 2024-02-10 16:34:52 -05:00
parent f8216cb0bd
commit 4710335750
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
3 changed files with 124 additions and 80 deletions

View File

@ -1,3 +1,4 @@
pub mod main_window_callbacks; pub mod main_window_callbacks;
pub mod new_plate_dialog_callbacks; pub mod new_plate_dialog_callbacks;
pub mod transfer_menu_callbacks; pub mod transfer_menu_callbacks;
pub mod tree_callbacks;

View File

@ -0,0 +1,114 @@
use std::rc::Rc;
use uuid::Uuid;
use wasm_bindgen::JsCast;
use web_sys::{EventTarget, HtmlElement};
use yew::prelude::*;
use yewdux::prelude::*;
use crate::components::states::{CurrentTransfer, MainState};
use crate::data::transfer_region::Region;
pub fn open_plate_info_callback(
plate_menu_id: UseStateHandle<Option<Uuid>>,
) -> Callback<MouseEvent> {
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
plate_menu_id.set(Some(Uuid::from_u128(id)));
}
}
})
}
pub fn plate_info_close_callback(
plate_menu_id: UseStateHandle<Option<Uuid>>,
) -> Callback<MouseEvent> {
Callback::from(move |_| {
plate_menu_id.set(None);
})
}
pub fn plate_info_delete_callback(
main_dispatch: Dispatch<MainState>,
plate_menu_id: UseStateHandle<Option<Uuid>>,
) -> Callback<MouseEvent> {
Callback::from(move |_| {
if let Some(id) = *plate_menu_id {
main_dispatch.reduce_mut(|state| {
state.del_plate(id);
});
}
})
}
pub fn source_plate_select_callback(
main_dispatch: Dispatch<MainState>,
ct_dispatch: Dispatch<CurrentTransfer>,
) -> Callback<MouseEvent> {
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
ct_dispatch.reduce_mut(|state| {
state.transfer.transfer_region.source_region = Region::default();
state.transfer.transfer_region.dest_region = Region::default();
});
main_dispatch.reduce_mut(|state| {
state.selected_source_plate = Uuid::from_u128(id);
state.selected_transfer = Uuid::nil();
});
}
}
})
}
pub fn destination_plate_select_callback(
main_dispatch: Dispatch<MainState>,
ct_dispatch: Dispatch<CurrentTransfer>,
) -> Callback<MouseEvent> {
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
ct_dispatch.reduce_mut(|state| {
state.transfer.transfer_region.source_region = Region::default();
state.transfer.transfer_region.dest_region = Region::default();
});
main_dispatch.reduce_mut(|state| {
state.selected_dest_plate = Uuid::from_u128(id);
state.selected_transfer = Uuid::nil();
});
}
}
})
}
pub fn transfer_select_callback(main_state: Rc<MainState>) -> Callback<MouseEvent> {
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
let id = Uuid::from_u128(id);
if let Some(transfer) = main_state
.transfers
.iter()
.find(|transfer| transfer.get_uuid() == id)
{
main_dispatch.reduce_mut(|state| {
state.selected_source_plate = transfer.source_id;
state.selected_dest_plate = transfer.dest_id;
state.selected_transfer = id;
});
ct_dispatch.reduce_mut(|state| {
state.transfer = transfer.clone();
});
}
}
}
})
}

View File

@ -2,12 +2,12 @@
use uuid::Uuid; use uuid::Uuid;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use web_sys::{EventTarget, HtmlDialogElement, HtmlElement, HtmlInputElement}; use web_sys::{HtmlDialogElement, HtmlInputElement};
use yew::prelude::*; use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::states::{CurrentTransfer, MainState}; use crate::components::states::{CurrentTransfer, MainState};
use crate::data::transfer_region::Region; use crate::components::callbacks::tree_callbacks;
#[derive(PartialEq, Properties)] #[derive(PartialEq, Properties)]
pub struct TreeProps { pub struct TreeProps {
@ -22,102 +22,31 @@ pub fn Tree(props: &TreeProps) -> Html {
let open_plate_info_callback = { let open_plate_info_callback = {
let plate_menu_id = plate_modal_id.clone(); let plate_menu_id = plate_modal_id.clone();
Callback::from(move |e: MouseEvent| { tree_callbacks::open_plate_info_callback(plate_menu_id)
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
plate_menu_id.set(Some(Uuid::from_u128(id)));
}
}
})
}; };
let plate_info_close_callback = { let plate_info_close_callback = {
let plate_menu_id = plate_modal_id.clone(); let plate_menu_id = plate_modal_id.clone();
Callback::from(move |_| { tree_callbacks::plate_info_close_callback(plate_menu_id)
plate_menu_id.set(None);
})
}; };
let plate_info_delete_callback = { let plate_info_delete_callback = {
let dispatch = main_dispatch.clone(); let main_dispatch = main_dispatch.clone();
let plate_menu_id = plate_modal_id.clone(); let plate_menu_id = plate_modal_id.clone();
Callback::from(move |_| { tree_callbacks::plate_info_delete_callback(main_dispatch, plate_menu_id)
if let Some(id) = *plate_menu_id {
dispatch.reduce_mut(|state| {
state.del_plate(id);
});
}
})
}; };
let source_plate_select_callback = { let source_plate_select_callback = {
let main_dispatch = main_dispatch.clone(); let main_dispatch = main_dispatch.clone();
let ct_dispatch = ct_dispatch.clone(); let ct_dispatch = ct_dispatch.clone();
tree_callbacks::source_plate_select_callback(main_dispatch, ct_dispatch)
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
ct_dispatch.reduce_mut(|state| {
state.transfer.transfer_region.source_region = Region::default();
state.transfer.transfer_region.dest_region = Region::default();
});
main_dispatch.reduce_mut(|state| {
state.selected_source_plate = Uuid::from_u128(id);
state.selected_transfer = Uuid::nil();
});
}
}
})
}; };
let destination_plate_select_callback = { let destination_plate_select_callback = {
let main_dispatch = main_dispatch.clone(); let main_dispatch = main_dispatch.clone();
let ct_dispatch = ct_dispatch.clone(); let ct_dispatch = ct_dispatch.clone();
tree_callbacks::destination_plate_select_callback(main_dispatch, ct_dispatch)
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
ct_dispatch.reduce_mut(|state| {
state.transfer.transfer_region.source_region = Region::default();
state.transfer.transfer_region.dest_region = Region::default();
});
main_dispatch.reduce_mut(|state| {
state.selected_dest_plate = Uuid::from_u128(id);
state.selected_transfer = Uuid::nil();
});
}
}
})
}; };
let transfer_select_callback = { let transfer_select_callback = {
let main_state = main_state.clone(); let main_state = main_state.clone();
tree_callbacks::transfer_select_callback(main_state)
Callback::from(move |e: MouseEvent| {
let target: Option<EventTarget> = e.target();
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
if let Some(li) = li {
if let Ok(id) = li.id().as_str().parse::<u128>() {
let id = Uuid::from_u128(id);
if let Some(transfer) = main_state
.transfers
.iter()
.find(|transfer| transfer.get_uuid() == id)
{
main_dispatch.reduce_mut(|state| {
state.selected_source_plate = transfer.source_id;
state.selected_dest_plate = transfer.dest_id;
state.selected_transfer = id;
});
ct_dispatch.reduce_mut(|state| {
state.transfer = transfer.clone();
});
}
}
}
})
}; };
let source_plates = main_state let source_plates = main_state