Allow renaming plates
This commit is contained in:
parent
2be8ad8661
commit
0e98e63c63
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
use web_sys::{EventTarget, HtmlDialogElement, HtmlElement};
|
use web_sys::{EventTarget, HtmlDialogElement, HtmlElement, HtmlInputElement};
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
use yewdux::prelude::*;
|
use yewdux::prelude::*;
|
||||||
|
|
||||||
|
@ -210,15 +210,15 @@ struct PlateInfoModalProps {
|
||||||
|
|
||||||
#[function_component]
|
#[function_component]
|
||||||
fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
||||||
let (state, dispatch) = use_store::<MainState>();
|
let (main_state, main_dispatch) = use_store::<MainState>();
|
||||||
let dialog_ref = use_node_ref();
|
let dialog_ref = use_node_ref();
|
||||||
|
|
||||||
let mut plate = state
|
let mut plate = main_state
|
||||||
.source_plates
|
.source_plates
|
||||||
.iter()
|
.iter()
|
||||||
.find(|spi| spi.get_uuid() == props.id);
|
.find(|spi| spi.get_uuid() == props.id);
|
||||||
if plate == None {
|
if plate == None {
|
||||||
plate = state
|
plate = main_state
|
||||||
.destination_plates
|
.destination_plates
|
||||||
.iter()
|
.iter()
|
||||||
.find(|dpi| dpi.get_uuid() == props.id);
|
.find(|dpi| dpi.get_uuid() == props.id);
|
||||||
|
@ -232,6 +232,19 @@ fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
||||||
move |_| dialog_close_callback.emit(())
|
move |_| dialog_close_callback.emit(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let rename_onchange = {
|
||||||
|
let main_dispatch = main_dispatch.clone();
|
||||||
|
let id = props.id;
|
||||||
|
Callback::from(move |e: Event| {
|
||||||
|
log::debug!("Changed name");
|
||||||
|
let input = e.target().expect("Event must have target")
|
||||||
|
.dyn_into::<HtmlInputElement>().unwrap();
|
||||||
|
main_dispatch.reduce_mut(|state| {
|
||||||
|
state.rename_plate(id, &input.value())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
let delete_onclick = {
|
let delete_onclick = {
|
||||||
let delete_button_callback = props.delete_button_callback.clone();
|
let delete_button_callback = props.delete_button_callback.clone();
|
||||||
let dialog_ref = dialog_ref.clone();
|
let dialog_ref = dialog_ref.clone();
|
||||||
|
@ -257,9 +270,9 @@ fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
||||||
}
|
}
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<dialog ref={dialog_ref} class="dialog" onclose={onclose}>
|
<dialog id="crab" ref={dialog_ref} class="dialog" onclose={onclose}>
|
||||||
<h2>{"Plate Info"}</h2>
|
<h2>{"Plate Info"}</h2>
|
||||||
<h3>{"Name: "}<input type="text" value={plate_name} /></h3>
|
<h3 id="horse">{"Name: "}<input type="text" id="shrimp" value={plate_name} onchange={rename_onchange}/></h3>
|
||||||
<button onclick={delete_onclick}>{"Delete"}</button>
|
<button onclick={delete_onclick}>{"Delete"}</button>
|
||||||
</dialog>
|
</dialog>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue