#![allow(non_snake_case)] use std::fmt::format; use wasm_bindgen::JsCast; use web_sys::{EventTarget, HtmlFormElement, FormData}; use yew::prelude::*; use yewdux::prelude::*; use crate::data::{plate_instances::PlateInstance, transfer::Transfer}; use crate::data::plate::*; use crate::components::states::MainState; #[function_component] pub fn Tree() -> Html { let (state, dispatch) = use_store::(); let source_plates = state.source_plates.iter() .map(|spi| { html!{
  • {String::from(spi)}
  • } }).collect::(); let dest_plates = state.destination_plates.iter() .map(|spi| { html!{
  • {String::from(spi)}
  • } }).collect::(); let new_plate_callback = { let dispatch = dispatch.clone(); Callback::from(move |e: SubmitEvent| { e.prevent_default(); let target: Option = e.target(); let form = target.and_then(|t| t.dyn_into::().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() { "384" => PlateFormat::W384, "96" => PlateFormat::W96, _ => PlateFormat::W6, }; let plate_type = match form_data.get("new_plate_type").as_string().unwrap().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)) } }); } } }) }; html! {

    {"Source Plates:"}

      {source_plates}

    {"Destination Plates:"}

      {dest_plates}

    {"Transfers:"}

    // Temporary
    } } impl From<&PlateInstance> for String { fn from(value: &PlateInstance) -> Self { // Could have other formatting here format!("{}, {}", value.name, value.plate.plate_format) } }