From 94a0e361e180223adf2bc9760c8810dfa3c2681f Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 28 Jan 2021 22:24:32 +0100 Subject: use different vcard library --- src/view/main.rs | 109 +++++++++++++------------------------------------------ 1 file changed, 25 insertions(+), 84 deletions(-) (limited to 'src/view/main.rs') 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, download: Option, selected_option: DownloadOption, - vcard: Option, + vcard_builder: VcardBuilder, name_links: Vec>, address_links: Vec>, @@ -36,10 +40,10 @@ pub enum Msg { ChangeDownloadOption(DownloadOption), Generate, - GeneratedFormattedName(Result), - GeneratedName(Result), - GeneratedAddress(Result), - GeneratedTelephone(Result), + 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) => { -- cgit v1.2.3