diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-01-28 22:24:32 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-01-28 22:24:32 +0100 |
commit | 94a0e361e180223adf2bc9760c8810dfa3c2681f (patch) | |
tree | d29de5300d0ff0ba636f48eca8df43bb5256b49c /src/view | |
parent | 3f0892368bcf475fdae39f24ef51b82b3013535f (diff) | |
download | wasm-card-94a0e361e180223adf2bc9760c8810dfa3c2681f.tar.gz wasm-card-94a0e361e180223adf2bc9760c8810dfa3c2681f.tar.bz2 |
use different vcard library
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/address.rs | 17 | ||||
-rw-r--r-- | src/view/main.rs | 109 | ||||
-rw-r--r-- | src/view/mod.rs | 5 | ||||
-rw-r--r-- | src/view/name.rs | 27 | ||||
-rw-r--r-- | src/view/telephone.rs | 16 |
5 files changed, 39 insertions, 135 deletions
diff --git a/src/view/address.rs b/src/view/address.rs index b833518..23b697a 100644 --- a/src/view/address.rs +++ b/src/view/address.rs @@ -1,11 +1,11 @@ use super::WeakComponentLink; use yew::prelude::*; -use vcard::properties; use crate::viewmodel::address::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; use crate::viewmodel::Error; + pub struct AddressView { props: Props, value: Address, @@ -28,11 +28,11 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback<Result<properties::Address,()>>, + pub generated: Callback<Address>, pub weak_link: WeakComponentLink<AddressView>, } -impl VCardPropertyInputComponent<properties::Address, Address> for AddressView { +impl VCardPropertyInputComponent<Address> for AddressView { fn get_input_object(&self) -> Address { self.value.clone() } @@ -67,16 +67,7 @@ impl Component for AddressView { Msg::ToggleWork => self.value.work = !self.value.work, Msg::ToggleHome => self.value.home = !self.value.home, Generate => { - match self.value.to_vcard_property() { - Ok(address) => { - self.props.generated.emit(Ok(address)); - return false; - }, - Err(error) => { - self.props.generated.emit(Err(())); - self.error = Some(error); - }, - }; + self.props.generated.emit(self.value); }, }; true diff --git a/src/view/main.rs b/src/view/main.rs index ce8c283..e926504 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -9,8 +9,12 @@ use genpdf::{elements, style, fonts}; use qrcodegen::QrCode; use qrcodegen::QrCodeEcc; use yew::prelude::*; -use vcard::properties; -use vcard::{VCard, VCardError}; +use vobject::Vcard; +use vobject::vcard::VcardBuilder; +use vobject::parameters; +use crate::viewmodel::name::Name; +use crate::viewmodel::address::Address; +use crate::viewmodel::telephone::Telephone; use crate::viewmodel::utility::*; @@ -19,7 +23,7 @@ pub struct MainView { error: Option<Error>, download: Option<Download>, selected_option: DownloadOption, - vcard: Option<VCard>, + vcard_builder: VcardBuilder, name_links: Vec<WeakComponentLink<NameView>>, address_links: Vec<WeakComponentLink<AddressView>>, @@ -36,10 +40,10 @@ pub enum Msg { ChangeDownloadOption(DownloadOption), Generate, - GeneratedFormattedName(Result<properties::FormattedName,()>), - GeneratedName(Result<properties::Name,()>), - GeneratedAddress(Result<properties::Address,()>), - GeneratedTelephone(Result<properties::Telephone,()>), + GeneratedFormattedName(String), + GeneratedName(Name), + GeneratedAddress(Address), + GeneratedTelephone(Telephone), GenerationComplete, Nope, @@ -55,7 +59,7 @@ impl Component for MainView { error: None, download: None, selected_option: DownloadOption::VCard, - vcard: None, + vcard_builder: VcardBuilder::new(), name_links: vec![WeakComponentLink::default()], address_links: vec![WeakComponentLink::default()], @@ -126,31 +130,7 @@ impl Component for MainView { self.answer_count += 1; - match formatted_name { - Ok(formatted_name) => { - match &mut self.vcard { - None => { - match VCard::from_formatted_name(formatted_name) { - Ok(vcard) => self.vcard = Some(vcard), - Err(VCardError::FormatError(err)) => { - self.error = Some(Error{ - msg: err.to_string(), - }); - }, - Err(VCardError::EmptyFormatName) => { - self.error= Some(Error{ - msg: String::from("At least one of the name fields should be filled out."), - }); - }, - }; - }, - Some(vcard) => { - vcard.formatted_names.insert(formatted_name); - }, - }; - }, - Err(_) => (), - }; + self.vcard_builder = self.vcard_builder.with_fullname(formatted_name); shouldrender = true; }, @@ -158,31 +138,14 @@ impl Component for MainView { self.answer_count += 1; - match name { - Ok(name) => { - match self.vcard { - Some(vcard) => { - match vcard.names { - Some(names) => { - names.insert(name); - }, - None => { - let names = { - let mut names = HashSet::new(); - names.insert(name); - - names - }; - - vcard.names = Some(vcard::Set::from_hash_set(names).unwrap()); - } - }; - }, - None => (), - }; - }, - Err(_) => (), - }; + self.vcard_builder = self.vcard_builder.with_name( + parameters!(), + name.last_name.is_empty().then(|| name.last_name), + name.first_name.is_empty().then(|| name.first_name), + name.middle_name.is_empty().then(|| name.middle_name), + name.prefix.is_empty().then(|| name.prefix), + name.suffix.is_empty().then(|| name.suffix) + ); shouldrender = true; @@ -191,32 +154,10 @@ impl Component for MainView { self.answer_count += 1; - match address { - Ok(address) => { - match self.vcard { - Some(vcard) => { - match vcard.addresses { - Some(addresses) => { - addresses.insert(address); - }, - None => { - let addresses = { - let mut addresses = HashSet::new(); - addresses.insert(address); - - addresses - }; - - vcard.addresses = Some(vcard::Set::from_hash_set(addresses).unwrap()); - } - }; - }, - None => (), - }; - }, - Err(_) => (), - }; - + self.vcard_builder = self.vcard_builder.with_adr( + parameters!(), + ); + shouldrender = true; }, Msg::GeneratedTelephone(telephone) => { diff --git a/src/view/mod.rs b/src/view/mod.rs index f208c44..7a64fed 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -9,10 +9,7 @@ pub mod name; pub mod address; pub mod telephone; -pub trait VCardPropertyInputComponent<P, T>: Component - where P: vcard::properties::Property, - T: VCardPropertyInputObject<P, Self> -{ +pub trait VCardPropertyInputComponent<T: VCardPropertyInputObject<Self>>: Component { fn get_input_object(&self) -> T; fn get_title(&self) -> String; fn get_error(&self) -> Option<Error>; diff --git a/src/view/name.rs b/src/view/name.rs index df3fb15..bee9256 100644 --- a/src/view/name.rs +++ b/src/view/name.rs @@ -1,7 +1,7 @@ use crate::viewmodel::Error; use crate::view::WeakComponentLink; use yew::prelude::*; -use vcard::properties; +use vobject::Property; use crate::viewmodel::name::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; @@ -24,12 +24,12 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated_name: Callback<Result<properties::Name,()>>, - pub generated_fn: Callback<Result<properties::FormattedName,()>>, + pub generated_name: Callback<Name>, + pub generated_fn: Callback<String>, pub weak_link: WeakComponentLink<NameView>, } -impl VCardPropertyInputComponent<properties::Name, Name> for NameView { +impl VCardPropertyInputComponent<Name> for NameView { fn get_input_object(&self) -> Name { self.value.clone() } @@ -60,23 +60,8 @@ impl Component for NameView { Msg::UpdateLastName(l) => self.value.last_name = l, Msg::UpdateSuffix(s) => self.value.suffix = s, Generate => { - match self.value.formatted_name() { - Ok(formatted_name) => self.props.generated_fn.emit(Ok(formatted_name)), - Err(error) => { - self.props.generated_fn.emit(Err(())); - self.error = Some(error); - }, - }; - match self.value.to_vcard_property() { - Ok(name) => { - self.props.generated_name.emit(Ok(name)); - return false; - }, - Err(error) => { - self.props.generated_name.emit(Err(())); - self.error = Some(error); - }, - }; + self.props.generated_fn.emit(self.value.generate_fn()); + self.props.generated_name.emit(self.value); }, }; true diff --git a/src/view/telephone.rs b/src/view/telephone.rs index a47c610..26d7806 100644 --- a/src/view/telephone.rs +++ b/src/view/telephone.rs @@ -1,7 +1,6 @@ use crate::view::WeakComponentLink; use crate::viewmodel::Error; use yew::prelude::*; -use vcard::properties; use crate::viewmodel::telephone::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; @@ -30,11 +29,11 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback<Result<properties::Telephone,()>>, + pub generated: Callback<Telephone>, pub weak_link: WeakComponentLink<TelephoneView>, } -impl VCardPropertyInputComponent<properties::Telephone, Telephone> for TelephoneView { +impl VCardPropertyInputComponent<Telephone> for TelephoneView { fn get_input_object(&self) -> Telephone { self.value.clone() } @@ -71,16 +70,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 => { - match self.value.to_vcard_property() { - Ok(telephone) => { - self.props.generated.emit(Ok(telephone)); - return false; - }, - Err(error) => { - self.props.generated.emit(Err(())); - self.error = Some(error); - }, - }; + self.props.generated.emit(self.value); } }; true |