diff options
Diffstat (limited to 'src/view/main.rs')
-rw-r--r-- | src/view/main.rs | 194 |
1 files changed, 115 insertions, 79 deletions
diff --git a/src/view/main.rs b/src/view/main.rs index 9b6a345..83acc3f 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -2,6 +2,7 @@ use yew::services::ConsoleService; use crate::viewmodel::vcard::VCardData; use crate::viewmodel::Error; use crate::view::telephone::{self,TelephoneView}; +use crate::viewmodel::VCardPropertyInputObject; use super::WeakComponentLink; use super::name::{self,NameView}; use super::address::{self,AddressView}; @@ -172,102 +173,137 @@ impl Component for MainView { for name in vcard_data.names { - builder = builder - .with_fullname( - name.generate_fn() - ) - .with_name( - parameters!(), - name.last_name.is_empty().as_some(name.last_name.clone()), - name.first_name.is_empty().as_some(name.first_name.clone()), - name.middle_name.is_empty().as_some(name.middle_name.clone()), - name.prefix.is_empty().as_some(name.prefix.clone()), - name.suffix.is_empty().as_some(name.suffix.clone()) - ); + if !name.is_empty() { + + builder = builder + .with_fullname( + name.generate_fn() + ) + .with_name( + parameters!(), + (!name.last_name.is_empty()) + .as_some(name.last_name.clone()), + (!name.first_name.is_empty()) + .as_some(name.first_name.clone()), + (!name.middle_name.is_empty()) + .as_some(name.middle_name.clone()), + (!name.prefix.is_empty()) + .as_some(name.prefix.clone()), + (!name.suffix.is_empty()) + .as_some(name.suffix.clone()) + ); + } } for address in vcard_data.addresses { - let mut types = String::new(); - if address.work { - types.push_str("WORK"); - } - if address.home { - if types.is_empty() { - types.push(','); + + if !address.is_empty() { + + let mut types = String::new(); + if address.work { + types.push_str("WORK"); } - types.push_str("HOME") + if address.home { + if !types.is_empty() { + types.push(','); + } + types.push_str("HOME") + } + + let params = if types.is_empty() { + parameters!() + } else { + parameters!("TYPE" => types) + }; + + builder = builder.with_adr( + params, + (!address.post_office_box.is_empty()) + .as_some(address.post_office_box.clone()), + (!address.extension.is_empty()) + .as_some(address.extension.clone()), + (!address.street.is_empty()) + .as_some(address.street.clone()), + (!address.locality.is_empty()) + .as_some(address.locality.clone()), + (!address.region.is_empty()) + .as_some(address.region.clone()), + (!address.code.is_empty()) + .as_some(address.code.clone()), + (!address.country.is_empty()) + .as_some(address.country.clone()), + ); } - - builder = builder.with_adr( - parameters!("TYPE" => types), - address.post_office_box.is_empty().as_some(address.post_office_box.clone()), - address.extension.is_empty().as_some(address.extension.clone()), - address.street.is_empty().as_some(address.street.clone()), - address.locality.is_empty().as_some(address.locality.clone()), - address.region.is_empty().as_some(address.region.clone()), - address.code.is_empty().as_some(address.code.clone()), - address.country.is_empty().as_some(address.country.clone()), - ); } for telephone in vcard_data.telephones { - let mut types = String::new(); - if telephone.work { - types.push_str("WORK"); - } - if telephone.home { - if types.is_empty() { - types.push(','); + + if !telephone.is_empty() { + + let mut types = String::new(); + if telephone.work { + types.push_str("WORK"); } - types.push_str("HOME") - } - if telephone.text { - if types.is_empty() { - types.push(','); + if telephone.home { + if !types.is_empty() { + types.push(','); + } + types.push_str("HOME") } - types.push_str("TEXT") - } - if telephone.voice { - if types.is_empty() { - types.push(','); + if telephone.text { + if !types.is_empty() { + types.push(','); + } + types.push_str("TEXT") } - types.push_str("VOICE") - } - if telephone.fax { - if types.is_empty() { - types.push(','); + if telephone.voice { + if !types.is_empty() { + types.push(','); + } + types.push_str("VOICE") } - types.push_str("FAX") - } - if telephone.cell { - if types.is_empty() { - types.push(','); + if telephone.fax { + if !types.is_empty() { + types.push(','); + } + types.push_str("FAX") } - types.push_str("CELL") - } - if telephone.video { - if types.is_empty() { - types.push(','); + if telephone.cell { + if !types.is_empty() { + types.push(','); + } + types.push_str("CELL") } - types.push_str("VIDEO") - } - if telephone.pager { - if types.is_empty() { - types.push(','); + if telephone.video { + if !types.is_empty() { + types.push(','); + } + types.push_str("VIDEO") } - types.push_str("PAGER") - } - if telephone.text_phone { - if types.is_empty() { - types.push(','); + if telephone.pager { + if !types.is_empty() { + types.push(','); + } + types.push_str("PAGER") } - types.push_str("TEXTPHONE") + if telephone.text_phone { + if !types.is_empty() { + types.push(','); + } + types.push_str("TEXTPHONE") + } + + let params = if types.is_empty() { + parameters!() + } else { + parameters!("TYPE" => types) + }; + + builder = builder.with_tel( + params, + telephone.number.clone(), + ); } - - builder = builder.with_tel( - parameters!("TYPE" => types), - telephone.number.clone(), - ); } |