diff --git a/src/components/main_window.rs b/src/components/main_window.rs index 39d56cd..fc9d5bd 100644 --- a/src/components/main_window.rs +++ b/src/components/main_window.rs @@ -1,12 +1,33 @@ #![allow(non_snake_case)] use yew::prelude::*; +use yewdux::prelude::*; + +use super::states::{MainState, NewTransferState}; use super::plates::plate_container::PlateContainer; use super::tree::Tree; use super::transfer_menu::TransferMenu; use super::new_plate_dialog::NewPlateDialog; +use crate::data::plate_instances::PlateInstance; + #[function_component] pub fn MainWindow() -> Html { + let (main_state, main_dispatch) = use_store::(); + let (selection_state, selection_dispatch) = use_store::(); + + let source_plate_instance = main_state.source_plates.iter() + .find(|spi| {spi.get_uuid() == selection_state.source_id}); + let source_dims = match source_plate_instance { + Some(spi) => Some(spi.plate.size()), + None => None, + }; + let destination_plate_instance = main_state.destination_plates.iter() + .find(|dpi| {dpi.get_uuid() == selection_state.destination_id}); + let destination_dims = match destination_plate_instance { + Some(dpi) => Some(dpi.plate.size()), + None => None, + }; + let new_plate_dialog_is_open = use_state_eq(|| false); let new_plate_dialog_callback = { let new_plate_dialog_is_open = new_plate_dialog_is_open.clone(); @@ -25,7 +46,7 @@ pub fn MainWindow() -> Html {
- + if {*new_plate_dialog_is_open} { } diff --git a/src/components/plates/plate_container.rs b/src/components/plates/plate_container.rs index bb9186d..cd2c02f 100644 --- a/src/components/plates/plate_container.rs +++ b/src/components/plates/plate_container.rs @@ -1,25 +1,29 @@ #![allow(non_snake_case)] use yew::prelude::*; -use yewdux::prelude::*; -use super::super::states::MainState; use super::source_plate::SourcePlate; use super::destination_plate::DestinationPlate; #[derive(Properties, PartialEq)] pub struct PlateContainerProps { - pub source_dims: (u8,u8), - pub destination_dims: (u8,u8) + pub source_dims: Option<(u8,u8)>, + pub destination_dims: Option<(u8,u8)>, } #[function_component] pub fn PlateContainer(props: &PlateContainerProps) -> Html { - let (state, dispatch) = use_store::(); - html! {
- - + if let Some((w,h)) = props.source_dims { + + } else { +

{"No Source Plate Selected"}

+ } + if let Some((w,h)) = props.destination_dims { + + } else { +

{"No Destination Plate Selected"}

+ }
} } diff --git a/src/components/tree.rs b/src/components/tree.rs index 3fd0a3b..6638b16 100644 --- a/src/components/tree.rs +++ b/src/components/tree.rs @@ -9,6 +9,7 @@ use yewdux::prelude::*; use crate::data::{plate_instances::PlateInstance, transfer::Transfer}; use crate::data::plate::*; use crate::components::states::{MainState, NewTransferState}; +use crate::components::transfer_menu::RegionDisplay; #[derive(PartialEq, Properties)] pub struct TreeProps { @@ -57,7 +58,10 @@ pub fn Tree(props: &TreeProps) -> Html { let li = target.and_then(|t| t.dyn_into::().ok()); if let Some(li) = li { if let Ok(id) = u128::from_str_radix(li.id().as_str(), 10) { - dispatch.reduce_mut(|state| state.source_id = Uuid::from_u128(id)) + dispatch.reduce_mut(|state| { + state.source_region = RegionDisplay::default(); + state.source_id = Uuid::from_u128(id); + }) } } }) @@ -69,7 +73,10 @@ pub fn Tree(props: &TreeProps) -> Html { let li = target.and_then(|t| t.dyn_into::().ok()); if let Some(li) = li { if let Ok(id) = u128::from_str_radix(li.id().as_str(), 10) { - dispatch.reduce_mut(|state| state.destination_id = Uuid::from_u128(id)) + dispatch.reduce_mut(|state| { + state.destination_region = RegionDisplay::default(); + state.destination_id = Uuid::from_u128(id); + }) } } }) diff --git a/src/data/plate.rs b/src/data/plate.rs index ed70d3a..6a08b9a 100644 --- a/src/data/plate.rs +++ b/src/data/plate.rs @@ -54,14 +54,14 @@ impl std::fmt::Display for PlateFormat { impl PlateFormat { pub fn size(&self) -> (u8, u8) { match self { - PlateFormat::W6 => (2, 3), - PlateFormat::W12 => (3, 4), - PlateFormat::W24 => (4, 6), - PlateFormat::W48 => (6, 8), - PlateFormat::W96 => (8, 12), - PlateFormat::W384 => (16, 24), - PlateFormat::W1536 => (32, 48), - PlateFormat::W3456 => (48, 72), + PlateFormat::W6 => (3, 2), + PlateFormat::W12 => (4, 3), + PlateFormat::W24 => (6, 4), + PlateFormat::W48 => (8, 6), + PlateFormat::W96 => (12, 8), + PlateFormat::W384 => (24, 16), + PlateFormat::W1536 => (48, 32), + PlateFormat::W3456 => (72, 48), } } }