Only modify NewTransferState by reduce_mut

This commit is contained in:
Emilia Allison 2023-05-24 15:49:07 -04:00
parent 1b0be78e85
commit 6e8c1eff55
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
3 changed files with 11 additions and 30 deletions

View File

@ -1,6 +1,7 @@
#![allow(non_snake_case)]
use yew::prelude::*;
use yewdux::prelude::*;
use std::intrinsics::discriminant_value;
use std::rc::Rc;
use super::super::states::NewTransferState;
@ -36,7 +37,6 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
};
let dispatch = Dispatch::<NewTransferState>::subscribe(menu_sync_callback);
let mouse_callback = {
let m_start_handle = m_start_handle.clone();
let m_end_handle = m_end_handle.clone();
@ -69,13 +69,9 @@ pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
if let Some(ul) = *m_start_handle {
if let Some(br) = *m_end_handle {
if let Ok(rd) = RegionDisplay::try_from((ul.0, ul.1, br.0, br.1)) {
dispatch.set(NewTransferState {
source_id: current.source_id,
destination_id: current.destination_id,
source_region: current.source_region.clone(),
destination_region: rd,
interleave_x: current.interleave_x,
interleave_y: current.interleave_y })
dispatch.reduce_mut(|state| {
state.destination_region = rd;
});
}
}
}

View File

@ -64,18 +64,13 @@ pub fn SourcePlate(props: &SourcePlateProps) -> Html {
let m_stat_handle = m_stat_handle.clone();
Callback::from(move |_: MouseEvent| {
let current = dispatch.get();
m_stat_handle.set(false);
if let Some(ul) = *m_start_handle {
if let Some(br) = *m_end_handle {
if let Ok(rd) = RegionDisplay::try_from((ul.0, ul.1, br.0, br.1)) {
dispatch.set(NewTransferState {
source_id: current.source_id,
destination_id: current.destination_id,
source_region: rd,
destination_region: current.destination_region.clone(),
interleave_x: current.interleave_x,
interleave_y: current.interleave_y })
dispatch.reduce_mut(|state| {
state.source_region = rd;
});
}
}
}

View File

@ -24,13 +24,8 @@ pub fn TransferMenu() -> Html {
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
if let Some(input) = input {
if let Ok(rd) = RegionDisplay::try_from(input.value()) {
dispatch.set( NewTransferState {
source_id: state.source_id,
destination_id: state.destination_id,
source_region: rd,
destination_region: state.destination_region.clone(),
interleave_x: state.interleave_x,
interleave_y: state.interleave_y
dispatch.reduce_mut(|state| {
state.source_region = rd;
});
input.set_custom_validity("");
} else {
@ -49,13 +44,8 @@ pub fn TransferMenu() -> Html {
let input = target.and_then(|t| t.dyn_into::<HtmlInputElement>().ok());
if let Some(input) = input {
if let Ok(rd) = RegionDisplay::try_from(input.value()) {
dispatch.set( NewTransferState {
source_id: state.source_id,
destination_id: state.destination_id,
source_region: state.source_region.clone(),
destination_region: rd,
interleave_x: state.interleave_x,
interleave_y: state.interleave_y
dispatch.reduce_mut(|state| {
state.destination_region = rd;
});
input.set_custom_validity("");
} else {