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/address.rs | 17 ++------ src/view/main.rs | 109 ++++++++++++-------------------------------------- src/view/mod.rs | 5 +-- src/view/name.rs | 27 +++---------- src/view/telephone.rs | 16 ++------ 5 files changed, 39 insertions(+), 135 deletions(-) (limited to 'src/view') 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>, + pub generated: Callback
, pub weak_link: WeakComponentLink, } -impl VCardPropertyInputComponent for AddressView { +impl VCardPropertyInputComponent
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, 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) => { 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: Component - where P: vcard::properties::Property, - T: VCardPropertyInputObject -{ +pub trait VCardPropertyInputComponent>: Component { fn get_input_object(&self) -> T; fn get_title(&self) -> String; fn get_error(&self) -> Option; 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>, - pub generated_fn: Callback>, + pub generated_name: Callback, + pub generated_fn: Callback, pub weak_link: WeakComponentLink, } -impl VCardPropertyInputComponent for NameView { +impl VCardPropertyInputComponent 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>, + pub generated: Callback, pub weak_link: WeakComponentLink, } -impl VCardPropertyInputComponent for TelephoneView { +impl VCardPropertyInputComponent 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 -- cgit v1.2.3