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/main.rs | |
parent | 3f0892368bcf475fdae39f24ef51b82b3013535f (diff) | |
download | wasm-card-94a0e361e180223adf2bc9760c8810dfa3c2681f.tar.gz wasm-card-94a0e361e180223adf2bc9760c8810dfa3c2681f.tar.bz2 |
use different vcard library
Diffstat (limited to 'src/view/main.rs')
-rw-r--r-- | src/view/main.rs | 109 |
1 files changed, 25 insertions, 84 deletions
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) => { |