Remove NewTransferState
It was bad not very good design! Use CurrentTransfer instead.
This commit is contained in:
parent
a1a0430ec3
commit
aee565dbb3
|
@ -2,7 +2,7 @@
|
|||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use super::states::{MainState, NewTransferState, CurrentTransfer};
|
||||
use super::states::{MainState, CurrentTransfer};
|
||||
use super::plates::plate_container::PlateContainer;
|
||||
use super::tree::Tree;
|
||||
use super::transfer_menu::TransferMenu;
|
||||
|
@ -13,11 +13,10 @@ use crate::data::plate_instances::PlateInstance;
|
|||
#[function_component]
|
||||
pub fn MainWindow() -> Html {
|
||||
let (main_state, main_dispatch) = use_store::<MainState>();
|
||||
let (selection_state, selection_dispatch) = use_store::<NewTransferState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
|
||||
let source_plate_instance: Option<PlateInstance> = main_state.source_plates.iter()
|
||||
.find(|spi| {spi.get_uuid() == selection_state.source_id})
|
||||
.find(|spi| {spi.get_uuid() == main_state.selected_source_plate})
|
||||
.cloned();
|
||||
if let Some(spi) = source_plate_instance.clone() {
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
|
@ -25,7 +24,7 @@ pub fn MainWindow() -> Html {
|
|||
});
|
||||
}
|
||||
let destination_plate_instance: Option<PlateInstance> = main_state.destination_plates.iter()
|
||||
.find(|dpi| {dpi.get_uuid() == selection_state.destination_id})
|
||||
.find(|dpi| {dpi.get_uuid() == main_state.selected_dest_plate})
|
||||
.cloned();
|
||||
if let Some(dpi) = destination_plate_instance.clone() {
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::rc::Rc;
|
|||
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
use crate::data::transfer_region::{TransferRegion, Region};
|
||||
use crate::components::states::{NewTransferState, CurrentTransfer};
|
||||
use crate::components::states::{CurrentTransfer};
|
||||
|
||||
use super::super::transfer_menu::RegionDisplay;
|
||||
|
||||
|
@ -17,7 +17,6 @@ pub struct DestinationPlateProps {
|
|||
|
||||
#[function_component]
|
||||
pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
|
||||
let (state, dispatch) = use_store::<NewTransferState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
let m_start_handle: UseStateHandle<Option<(u8,u8)>> = use_state_eq(|| None);
|
||||
let m_end_handle: UseStateHandle<Option<(u8,u8)>> = use_state_eq(|| None);
|
||||
|
@ -26,8 +25,10 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
|
|||
let m_end = m_end_handle.clone();
|
||||
|
||||
if !(*m_stat_handle) {
|
||||
let pt1 = (state.destination_region.col_start, state.destination_region.row_start);
|
||||
let pt2 = (state.destination_region.col_end, state.destination_region.row_end);
|
||||
let (pt1, pt2) = match ct_state.transfer.dest_region {
|
||||
Region::Point((x,y)) => ((x,y),(x,y)),
|
||||
Region::Rect(c1, c2) => (c1, c2),
|
||||
};
|
||||
m_start_handle.set(Some(pt1));
|
||||
m_end_handle.set(Some(pt2));
|
||||
}
|
||||
|
@ -67,9 +68,6 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
|
|||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.dest_region = Region::from(&rd);
|
||||
});
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.destination_region = rd;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::rc::Rc;
|
|||
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
use crate::data::transfer_region::{TransferRegion, Region};
|
||||
use crate::components::states::{NewTransferState, CurrentTransfer};
|
||||
use crate::components::states::{CurrentTransfer};
|
||||
|
||||
use super::super::transfer_menu::RegionDisplay;
|
||||
|
||||
|
@ -18,7 +18,6 @@ pub struct SourcePlateProps {
|
|||
|
||||
#[function_component]
|
||||
pub fn SourcePlate(props: &SourcePlateProps) -> Html {
|
||||
let (state, dispatch) = use_store::<NewTransferState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
let m_start_handle: UseStateHandle<Option<(u8,u8)>> = use_state_eq(|| None);
|
||||
let m_end_handle: UseStateHandle<Option<(u8,u8)>> = use_state_eq(|| None);
|
||||
|
@ -27,8 +26,10 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
|
|||
let m_end = m_end_handle.clone();
|
||||
|
||||
if !(*m_stat_handle) {
|
||||
let pt1 = (state.source_region.col_start, state.source_region.row_start);
|
||||
let pt2 = (state.source_region.col_end, state.source_region.row_end);
|
||||
let (pt1, pt2) = match ct_state.transfer.source_region {
|
||||
Region::Point((x,y)) => ((x,y),(x,y)),
|
||||
Region::Rect(c1, c2) => (c1, c2),
|
||||
};
|
||||
m_start_handle.set(Some(pt1));
|
||||
m_end_handle.set(Some(pt2));
|
||||
}
|
||||
|
@ -69,9 +70,6 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
|
|||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.source_region = Region::from(&rd);
|
||||
});
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.source_region = rd;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,17 +8,6 @@ use crate::data::transfer::Transfer;
|
|||
use crate::data::plate::*;
|
||||
use crate::data::transfer_region::TransferRegion;
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)]
|
||||
#[store(storage = "session")]
|
||||
pub struct NewTransferState {
|
||||
pub source_id: Uuid,
|
||||
pub destination_id: Uuid,
|
||||
pub source_region: RegionDisplay,
|
||||
pub destination_region: RegionDisplay,
|
||||
pub interleave_x: i8,
|
||||
pub interleave_y: i8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)]
|
||||
#[store(storage = "session")]
|
||||
pub struct CurrentTransfer {
|
||||
|
@ -30,6 +19,9 @@ pub struct MainState {
|
|||
pub source_plates: Vec<PlateInstance>,
|
||||
pub destination_plates: Vec<PlateInstance>,
|
||||
pub transfers: Vec<Transfer>,
|
||||
pub selected_source_plate: Uuid,
|
||||
pub selected_dest_plate: Uuid,
|
||||
pub selected_transfer: Uuid,
|
||||
}
|
||||
|
||||
impl Store for MainState {
|
||||
|
|
|
@ -10,15 +10,13 @@ use lazy_static::lazy_static;
|
|||
|
||||
use crate::data::transfer_region::Region;
|
||||
|
||||
use super::states::{NewTransferState, CurrentTransfer};
|
||||
use super::states::{CurrentTransfer};
|
||||
|
||||
#[function_component]
|
||||
pub fn TransferMenu() -> Html {
|
||||
let (state, dispatch) = use_store::<NewTransferState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
|
||||
let on_src_region_change = {
|
||||
let dispatch = dispatch.clone();
|
||||
let ct_dispatch = ct_dispatch.clone();
|
||||
|
||||
Callback::from(move |e: Event| {
|
||||
|
@ -29,9 +27,6 @@ pub fn TransferMenu() -> Html {
|
|||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.source_region = Region::from(&rd);
|
||||
});
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.source_region = rd;
|
||||
});
|
||||
input.set_custom_validity("");
|
||||
} else {
|
||||
input.set_custom_validity("Invalid region.")
|
||||
|
@ -40,7 +35,6 @@ pub fn TransferMenu() -> Html {
|
|||
})
|
||||
};
|
||||
let on_dest_region_change = {
|
||||
let dispatch = dispatch.clone();
|
||||
let ct_dispatch = ct_dispatch.clone();
|
||||
|
||||
Callback::from(move |e: Event| {
|
||||
|
@ -51,9 +45,6 @@ pub fn TransferMenu() -> Html {
|
|||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.dest_region = Region::from(&rd);
|
||||
});
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.destination_region = rd;
|
||||
});
|
||||
input.set_custom_validity("");
|
||||
} else {
|
||||
input.set_custom_validity("Invalid region.")
|
||||
|
@ -63,8 +54,6 @@ pub fn TransferMenu() -> Html {
|
|||
};
|
||||
|
||||
let on_dest_interleave_x_change = {
|
||||
let dispatch = dispatch.clone();
|
||||
let ct_state = ct_state.clone();
|
||||
let ct_dispatch = ct_dispatch.clone();
|
||||
|
||||
Callback::from(move |e: Event| {
|
||||
|
@ -72,9 +61,6 @@ pub fn TransferMenu() -> Html {
|
|||
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
|
||||
if let Some(input) = input {
|
||||
if let Ok(num) = input.value().parse::<i8>() {
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.interleave_x = num;
|
||||
});
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.interleave_dest = (num, state.transfer.interleave_dest.1);
|
||||
});
|
||||
|
@ -83,8 +69,6 @@ pub fn TransferMenu() -> Html {
|
|||
})
|
||||
};
|
||||
let on_dest_interleave_y_change = {
|
||||
let dispatch = dispatch.clone();
|
||||
let ct_state = ct_state.clone();
|
||||
let ct_dispatch = ct_dispatch.clone();
|
||||
|
||||
Callback::from(move |e: Event| {
|
||||
|
@ -92,9 +76,6 @@ pub fn TransferMenu() -> Html {
|
|||
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
|
||||
if let Some(input) = input {
|
||||
if let Ok(num) = input.value().parse::<i8>() {
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.interleave_y = num;
|
||||
});
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.interleave_dest = (state.transfer.interleave_dest.0, num);
|
||||
});
|
||||
|
@ -109,21 +90,23 @@ pub fn TransferMenu() -> Html {
|
|||
<div>
|
||||
<label for="src_region">{"Source Region:"}</label>
|
||||
<input type="text" name="src_region"
|
||||
onchange={on_src_region_change} value={state.source_region.text.clone()}/>
|
||||
onchange={on_src_region_change}
|
||||
value={RegionDisplay::from(&ct_state.transfer.source_region).text}/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="dest_region">{"Destination Region:"}</label>
|
||||
<input type="text" name="dest_region"
|
||||
onchange={on_dest_region_change} value={state.destination_region.text.clone()}/>
|
||||
onchange={on_dest_region_change}
|
||||
value={RegionDisplay::from(&ct_state.transfer.dest_region).text}/>
|
||||
</div>
|
||||
<div>
|
||||
{"Destination Interleave "}
|
||||
<label for="dest_interleave_x">{"X:"}</label>
|
||||
<input type="number" name="dest_interleave_x"
|
||||
onchange={on_dest_interleave_x_change} value={state.interleave_x.to_string()}/>
|
||||
onchange={on_dest_interleave_x_change} value={ct_state.transfer.interleave_dest.0.to_string()}/>
|
||||
<label for="dest_interleave_y">{"Y:"}</label>
|
||||
<input type="number" name="dest_interleave_y"
|
||||
onchange={on_dest_interleave_y_change} value={state.interleave_y.to_string()}/>
|
||||
onchange={on_dest_interleave_y_change} value={ct_state.transfer.interleave_dest.1.to_string()}/>
|
||||
</div>
|
||||
<input type="button" name="create_transfer" value={"Create"} />
|
||||
</form>
|
||||
|
@ -167,6 +150,15 @@ impl TryFrom<String> for RegionDisplay {
|
|||
}
|
||||
|
||||
}
|
||||
impl From<&Region> for RegionDisplay {
|
||||
fn from(value: &Region) -> Self {
|
||||
match *value {
|
||||
Region::Point((col, row)) => RegionDisplay::try_from((col,row,col,row)).ok().unwrap(),
|
||||
Region::Rect(c1, c2) =>
|
||||
RegionDisplay::try_from((c1.0,c1.1,c2.0,c2.1)).ok().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<&RegionDisplay> for Region {
|
||||
fn from(value: &RegionDisplay) -> Self {
|
||||
if value.col_start == value.col_end && value.row_start == value.row_end {
|
||||
|
|
|
@ -6,8 +6,9 @@ use web_sys::{EventTarget, HtmlElement, HtmlDialogElement};
|
|||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::{MainState, NewTransferState, CurrentTransfer};
|
||||
use crate::components::states::{MainState, CurrentTransfer};
|
||||
use crate::components::transfer_menu::RegionDisplay;
|
||||
use crate::data::transfer_region::Region;
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct TreeProps {
|
||||
|
@ -17,7 +18,7 @@ pub struct TreeProps {
|
|||
#[function_component]
|
||||
pub fn Tree(props: &TreeProps) -> Html {
|
||||
let (main_state, main_dispatch) = use_store::<MainState>();
|
||||
let (selection_state, selection_dispatch) = use_store::<NewTransferState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
let plate_modal_id: UseStateHandle<Option<Uuid>> = use_state(|| {None});
|
||||
|
||||
let open_plate_info_callback = {
|
||||
|
@ -50,31 +51,39 @@ pub fn Tree(props: &TreeProps) -> Html {
|
|||
})
|
||||
};
|
||||
let source_plate_select_callback = {
|
||||
let dispatch = selection_dispatch.clone();
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
let ct_dispatch = ct_dispatch.clone();
|
||||
|
||||
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) = u128::from_str_radix(li.id().as_str(), 10) {
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.source_region = RegionDisplay::default();
|
||||
state.source_id = Uuid::from_u128(id);
|
||||
})
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.source_region = Region::default();
|
||||
});
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.selected_source_plate = Uuid::from_u128(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
let destination_plate_select_callback = {
|
||||
let dispatch = selection_dispatch.clone();
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
let ct_dispatch = ct_dispatch.clone();
|
||||
|
||||
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) = u128::from_str_radix(li.id().as_str(), 10) {
|
||||
dispatch.reduce_mut(|state| {
|
||||
state.destination_region = RegionDisplay::default();
|
||||
state.destination_id = Uuid::from_u128(id);
|
||||
})
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.dest_region = Region::default();
|
||||
});
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.selected_dest_plate = Uuid::from_u128(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -86,7 +95,7 @@ pub fn Tree(props: &TreeProps) -> Html {
|
|||
ondblclick={open_plate_info_callback.clone()}
|
||||
onclick={source_plate_select_callback.clone()}
|
||||
class={classes!(
|
||||
Some(if spi.get_uuid() == selection_state.source_id {Some("selected")}
|
||||
Some(if spi.get_uuid() == main_state.selected_source_plate {Some("selected")}
|
||||
else {None})
|
||||
)}>
|
||||
{String::from(spi)}
|
||||
|
@ -98,7 +107,7 @@ pub fn Tree(props: &TreeProps) -> Html {
|
|||
ondblclick={open_plate_info_callback.clone()}
|
||||
onclick={destination_plate_select_callback.clone()}
|
||||
class={classes!(
|
||||
Some(if dpi.get_uuid() == selection_state.destination_id {Some("selected")}
|
||||
Some(if dpi.get_uuid() == main_state.selected_dest_plate {Some("selected")}
|
||||
else {None})
|
||||
)}> {String::from(dpi)} </li> }
|
||||
}).collect::<Html>();
|
||||
|
|
Loading…
Reference in New Issue