diff options
-rw-r--r-- | src/view/address.rs | 19 | ||||
-rw-r--r-- | src/view/main.rs | 21 | ||||
-rw-r--r-- | src/view/name.rs | 19 | ||||
-rw-r--r-- | src/view/telephone.rs | 19 | ||||
-rw-r--r-- | src/viewmodel/vcard.rs | 13 |
5 files changed, 28 insertions, 63 deletions
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<Address>, + value: Address, error: Option<Error>, } @@ -45,19 +42,13 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback<Irc<Address>>, + pub generated: Callback<Address>, pub weak_link: WeakComponentLink<AddressView>, } impl VCardPropertyInputComponent<Address> 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<Name>), - GeneratedAddress(Irc<Address>), - GeneratedTelephone(Irc<Telephone>), + 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!{ <NameView weak_link=link generated=self.link.callback( - |n: Irc<Name>| + |n: Name| Msg::GeneratedName(n) ) /> @@ -395,7 +388,7 @@ impl Component for MainView { html!{ <AddressView weak_link=link generated=self.link.callback( - |a: Irc<Address>| + |a: Address| Msg::GeneratedAddress(a) ) /> @@ -408,7 +401,7 @@ impl Component for MainView { html!{ <TelephoneView weak_link=link generated=self.link.callback( - |t: Irc<Telephone>| + |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<Name>, + value: Name, error: Option<Error>, } @@ -41,19 +38,13 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback<Irc<Name>>, + pub generated: Callback<Name>, pub weak_link: WeakComponentLink<NameView>, } impl VCardPropertyInputComponent<Name> 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<Telephone>, + value: Telephone, error: Option<Error>, } @@ -46,19 +43,13 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback<Irc<Telephone>>, + pub generated: Callback<Telephone>, pub weak_link: WeakComponentLink<TelephoneView>, } impl VCardPropertyInputComponent<Telephone> 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 diff --git a/src/viewmodel/vcard.rs b/src/viewmodel/vcard.rs index 0225590..2b81fd8 100644 --- a/src/viewmodel/vcard.rs +++ b/src/viewmodel/vcard.rs @@ -1,4 +1,3 @@ -use yewtil::ptr::Irc; use crate::viewmodel::telephone::Telephone; use crate::viewmodel::address::Address; use crate::viewmodel::name::Name; @@ -6,9 +5,9 @@ use crate::viewmodel::name::Name; /// Type that represents the data structure of a vcard. #[derive(Clone, Debug)] pub struct VCardData { - pub names: Vec<Irc<Name>>, - pub addresses: Vec<Irc<Address>>, - pub telephones: Vec<Irc<Telephone>>, + pub names: Vec<Name>, + pub addresses: Vec<Address>, + pub telephones: Vec<Telephone>, } macro_rules! make_vec_adder_fn { @@ -27,7 +26,7 @@ impl VCardData { telephones: Vec::new(), } } - make_vec_adder_fn!( fn add_name names => name: Irc<Name> ); - make_vec_adder_fn!( fn add_address addresses => address: Irc<Address> ); - make_vec_adder_fn!( fn add_telephone telephones => telephone: Irc<Telephone> ); + make_vec_adder_fn!( fn add_name names => name: Name ); + make_vec_adder_fn!( fn add_address addresses => address: Address ); + make_vec_adder_fn!( fn add_telephone telephones => telephone: Telephone ); }
\ No newline at end of file |