From 0c8f99f4f58953334731cc195c385d31d8b0f695 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 4 Feb 2021 16:26:56 +0100 Subject: it works! --- src/view/address.rs | 19 +++++-------------- src/view/main.rs | 21 +++++++-------------- src/view/name.rs | 19 +++++-------------- src/view/telephone.rs | 19 +++++-------------- 4 files changed, 22 insertions(+), 56 deletions(-) (limited to 'src/view') diff --git a/src/view/address.rs b/src/view/address.rs index 01c949b..1aedcbd 100644 --- a/src/view/address.rs +++ b/src/view/address.rs @@ -1,8 +1,5 @@ -use yew::services::ConsoleService; use yew::prelude::*; use yewtil::NeqAssign; -use yewtil::ptr::Irc; -use yewtil::ptr::Mrc; use super::WeakComponentLink; use crate::viewmodel::address::*; use crate::viewmodel::VCardPropertyInputObject; @@ -25,7 +22,7 @@ use crate::viewmodel::Error; /// ``` pub struct AddressView { props: Props, - value: Mrc
, + value: Address, error: Option, } @@ -45,19 +42,13 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback>, + pub generated: Callback
, pub weak_link: WeakComponentLink, } impl VCardPropertyInputComponent
for AddressView { fn get_input_object(&self) -> Address { - match self.value.irc().try_unwrap() { - Ok(address) => address, - Err(_) => { - ConsoleService::error("Couldn't unwrap address"); - Address::new() - }, - } + self.value.clone() } fn get_title(&self) -> String { "Address".to_string() @@ -74,7 +65,7 @@ impl Component for AddressView { props.weak_link.borrow_mut().replace(link); Self { props, - value: Mrc::new(Address::new()), + value: Address::new(), error: None, } } @@ -90,7 +81,7 @@ impl Component for AddressView { Msg::ToggleWork => self.value.work = !self.value.work, Msg::ToggleHome => self.value.home = !self.value.home, Msg::Generate => { - self.props.generated.emit(self.value.irc()); + self.props.generated.emit(self.value.clone()); }, }; true diff --git a/src/view/main.rs b/src/view/main.rs index b1c0dda..9b6a345 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -1,5 +1,4 @@ use yew::services::ConsoleService; -use yewtil::ptr::Irc; use crate::viewmodel::vcard::VCardData; use crate::viewmodel::Error; use crate::view::telephone::{self,TelephoneView}; @@ -44,9 +43,9 @@ pub enum Msg { ChangeDownloadOption(DownloadOption), Generate, - GeneratedName(Irc), - GeneratedAddress(Irc
), - GeneratedTelephone(Irc), + GeneratedName(Name), + GeneratedAddress(Address), + GeneratedTelephone(Telephone), GenerationComplete, Nope, @@ -167,13 +166,7 @@ impl Component for MainView { self.answer_count = 0; - let vcard_data = match self.vcard_data.irc().try_unwrap() { - Ok(data) => data, - Err(err) => { - ConsoleService::error(&format!("Error when unwrapping VCardData: {:?}", err)); - VCardData::new() - }, - }; + let vcard_data = self.vcard_data.clone_inner(); let mut builder = VcardBuilder::new(); @@ -382,7 +375,7 @@ impl Component for MainView { html!{ | + |n: Name| Msg::GeneratedName(n) ) /> @@ -395,7 +388,7 @@ impl Component for MainView { html!{ | + |a: Address| Msg::GeneratedAddress(a) ) /> @@ -408,7 +401,7 @@ impl Component for MainView { html!{ | + |t: Telephone| Msg::GeneratedTelephone(t) ) /> diff --git a/src/view/name.rs b/src/view/name.rs index d864e35..27dadf1 100644 --- a/src/view/name.rs +++ b/src/view/name.rs @@ -1,8 +1,5 @@ -use yew::services::ConsoleService; use yew::prelude::*; use yewtil::NeqAssign; -use yewtil::ptr::Irc; -use yewtil::ptr::Mrc; use crate::viewmodel::Error; use crate::view::WeakComponentLink; use crate::viewmodel::name::*; @@ -25,7 +22,7 @@ use super::VCardPropertyInputComponent; /// ``` pub struct NameView { props: Props, - value: Mrc, + value: Name, error: Option, } @@ -41,19 +38,13 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback>, + pub generated: Callback, pub weak_link: WeakComponentLink, } impl VCardPropertyInputComponent for NameView { fn get_input_object(&self) -> Name { - match self.value.clone().try_unwrap() { - Ok(name) => name, - Err(_) => { - ConsoleService::error("Couldn't unwrap name"); - Name::new() - }, - } + self.value.clone() } fn get_title(&self) -> String { "Name".to_string() @@ -70,7 +61,7 @@ impl Component for NameView { props.weak_link.borrow_mut().replace(link); Self { props, - value: Mrc::new(Name::new()), + value: Name::new(), error: None, } } @@ -82,7 +73,7 @@ impl Component for NameView { Msg::UpdateLastName(l) => self.value.last_name = l, Msg::UpdateSuffix(s) => self.value.suffix = s, Msg::Generate => { - self.props.generated.emit(self.value.irc()); + self.props.generated.emit(self.value.clone()); }, }; true diff --git a/src/view/telephone.rs b/src/view/telephone.rs index 63fdee7..5db8ae1 100644 --- a/src/view/telephone.rs +++ b/src/view/telephone.rs @@ -1,7 +1,4 @@ use yew::prelude::*; -use yew::services::ConsoleService; -use yewtil::ptr::Irc; -use yewtil::ptr::Mrc; use yewtil::NeqAssign; use crate::view::WeakComponentLink; use crate::viewmodel::Error; @@ -25,7 +22,7 @@ use super::VCardPropertyInputComponent; /// ``` pub struct TelephoneView { props: Props, - value: Mrc, + value: Telephone, error: Option, } @@ -46,19 +43,13 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback>, + pub generated: Callback, pub weak_link: WeakComponentLink, } impl VCardPropertyInputComponent for TelephoneView { fn get_input_object(&self) -> Telephone { - match self.value.irc().try_unwrap() { - Ok(telephone) => telephone, - Err(_) => { - ConsoleService::error("Couldn't unwrap telephone"); - Telephone::new() - }, - } + self.value.clone() } fn get_title(&self) -> String { "Telephone".to_string() @@ -75,7 +66,7 @@ impl Component for TelephoneView { props.weak_link.borrow_mut().replace(link); Self { props, - value: Mrc::new(Telephone::new()), + value: Telephone::new(), error: None, } } @@ -92,7 +83,7 @@ impl Component for TelephoneView { Msg::TogglePager => self.value.pager = !self.value.pager, Msg::ToggleTextPhone => self.value.text_phone = !self.value.text_phone, Msg::Generate => { - self.props.generated.emit(self.value.irc()); + self.props.generated.emit(self.value.clone()); } }; true -- cgit v1.2.3