Create new transfer

This commit is contained in:
Emilia Allison 2023-05-27 13:12:58 -04:00
parent 855506bd26
commit 2fd1b0ca77
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
4 changed files with 55 additions and 8 deletions

View File

@ -57,7 +57,7 @@ impl MainState {
dpi.get_uuid() == tr.dest_id
})
})
.map(|&tr| tr)
.map(|tr| tr.clone())
.collect();
}

View File

@ -8,12 +8,13 @@ use web_sys::{EventTarget, HtmlInputElement};
use regex::Regex;
use lazy_static::lazy_static;
use crate::data::transfer_region::Region;
use crate::data::{transfer_region::Region, transfer::Transfer};
use super::states::{CurrentTransfer};
use super::states::{MainState, CurrentTransfer};
#[function_component]
pub fn TransferMenu() -> Html {
let (main_state, main_dispatch) = use_store::<MainState>();
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
let on_src_region_change = {
@ -113,6 +114,35 @@ pub fn TransferMenu() -> Html {
}
})
};
let create_transfer_button_callback = {
let main_dispatch = main_dispatch.clone();
let main_state = main_state.clone();
let ct_state = ct_state.clone();
Callback::from(move |e: MouseEvent| {
log::debug!("Button pressed");
if main_state.selected_transfer.is_nil() {
log::debug!("Was nil");
if let Some(spi) = main_state.source_plates.iter()
.find(|spi| spi.get_uuid() == main_state.selected_source_plate) {
if let Some(dpi) = main_state.destination_plates.iter()
.find(|dpi| dpi.get_uuid() == main_state.selected_dest_plate) {
let new_transfer = Transfer::new(
spi.clone(),
dpi.clone(),
ct_state.transfer.clone(),
"Reginald".to_string());
main_dispatch.reduce_mut(|state| {
state.transfers.push(new_transfer)
});
}
}
//let new_transfer = Transfer::new();
main_dispatch.reduce_mut(|state| {
});
}
})
};
html! {
<div class="transfer_menu">
@ -149,9 +179,9 @@ pub fn TransferMenu() -> Html {
<input type="number" name="dest_interleave_y"
onchange={on_dest_interleave_y_change} value={ct_state.transfer.interleave_dest.1.to_string()}/>
</div>
<input type="button" name="create_transfer" value={"Create"} />
<input type="button" name="create_transfer" onclick={create_transfer_button_callback}
value={"Create"} />
</form>
<button>{"Refresh"}</button>
</div>
}
}

View File

@ -111,6 +111,14 @@ pub fn Tree(props: &TreeProps) -> Html {
else {None})
)}> {String::from(dpi)} </li> }
}).collect::<Html>();
let transfers = main_state.transfers.iter()
.map(|transfer| {
html!{ <li id={transfer.get_uuid().as_u128().to_string()}>
{transfer.name.clone()}
</li>
}
})
.collect::<Html>();
html! {
@ -130,6 +138,7 @@ pub fn Tree(props: &TreeProps) -> Html {
<div id="transfers">
<h3>{"Transfers:"}</h3>
<ul>
{transfers}
</ul>
</div>
if let Some(id) = *plate_modal_id {

View File

@ -4,19 +4,27 @@ use uuid::Uuid;
use super::transfer_region::*;
use super::plate_instances::*;
#[derive(PartialEq, Clone, Copy, Serialize, Deserialize)]
#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub struct Transfer {
pub source_id: Uuid,
pub dest_id: Uuid,
pub name: String,
id: Uuid,
pub transfer_region: TransferRegion,
}
impl Transfer {
fn new(source: PlateInstance, dest: PlateInstance, tr: TransferRegion) -> Self {
pub fn new(source: PlateInstance, dest: PlateInstance, tr: TransferRegion, name: String) -> Self {
Self {
source_id: source.get_uuid(),
dest_id: dest.get_uuid(),
transfer_region: tr
name,
id: Uuid::new_v4(),
transfer_region: tr,
}
}
pub fn get_uuid(&self) -> Uuid {
self.id
}
}