diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-04 18:18:24 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-04 18:18:24 +0100 |
commit | 021588157748556e2229e8c6a729c91fb608988b (patch) | |
tree | da354252d63425d160ff53319e1dca6f9ca656b1 | |
parent | 0c8f99f4f58953334731cc195c385d31d8b0f695 (diff) | |
download | wasm-card-021588157748556e2229e8c6a729c91fb608988b.tar.gz wasm-card-021588157748556e2229e8c6a729c91fb608988b.tar.bz2 |
fix some issues and add readme
-rw-r--r-- | Readme.md | 53 | ||||
-rw-r--r-- | snippets | 103 | ||||
-rw-r--r-- | src/view/main.rs | 194 |
3 files changed, 168 insertions, 182 deletions
diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..ca02f40 --- /dev/null +++ b/Readme.md @@ -0,0 +1,53 @@ +<div align="center"> + + <h1><code>wasmCard</code></h1> + <strong>An Online vCard Generator written in Rust.</strong> + +</div> + +## 📚 About + +A WebAssebmly Web App + +Supports generating vCards (.vcf), print-ready PDF business cards and QR Codes. + +## 🎮 Features + +* Supported properties as of yet: name, address, telephone +* Output and Download as vCard (.vcf) +* Output and Download as QR Code +* Generates a dummy PDF + +## 🗺 Roadmap + +* Add more properties +* Button for adding more of one type of property (Support is already there) +* Put generation and download both in download button +* Generate PDF + +## 🚲 Usage + +### 🛠️ Needed tools + +* [Standard rust toolchain](https://www.rust-lang.org/tools/install) +* [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) +* HTTP Server (python has one!) + + +### 📦 Build with `wasm-pack build` + +``` +wasm-pack build --target web +``` + +### 🔍 Use the debug flag for tracing errors + +``` +wasm-pack build --debug --target web +``` + +### 🎬 Run on python server + +``` +python -m http.server 8000 +```
\ No newline at end of file diff --git a/snippets b/snippets deleted file mode 100644 index dc4e601..0000000 --- a/snippets +++ /dev/null @@ -1,103 +0,0 @@ - - - match self.vcard_data.get_mut() { - Some(vcard_builder) => *vcard_builder = 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) - ), - None => (), - }; - - -------------------------------------------------------------- - - let mut types = String::new(); - if address.work { - types.push_str("WORK"); - } - if address.home { - if types.is_empty() { - types.push(','); - } - types.push_str("HOME") - } - - match self.vcard_data.get_mut() { - Some(vcard_builder) => *vcard_builder = vcard_builder.with_adr( - parameters!("TYPE" => types), - address.post_office_box.is_empty().then(|| address.post_office_box), - address.extension.is_empty().then(|| address.extension), - address.street.is_empty().then(|| address.street), - address.locality.is_empty().then(|| address.locality), - address.region.is_empty().then(|| address.region), - address.code.is_empty().then(|| address.code), - address.country.is_empty().then(|| address.country), - ), - None => (), - }; - - ---------------------------------------------------------------- - - let mut types = String::new(); - if telephone.work { - types.push_str("WORK"); - } - if telephone.home { - if types.is_empty() { - types.push(','); - } - types.push_str("HOME") - } - if telephone.text { - if types.is_empty() { - types.push(','); - } - types.push_str("TEXT") - } - if telephone.voice { - if types.is_empty() { - types.push(','); - } - types.push_str("VOICE") - } - if telephone.fax { - if types.is_empty() { - types.push(','); - } - types.push_str("FAX") - } - if telephone.cell { - if types.is_empty() { - types.push(','); - } - types.push_str("CELL") - } - if telephone.video { - if types.is_empty() { - types.push(','); - } - types.push_str("VIDEO") - } - if telephone.pager { - if types.is_empty() { - types.push(','); - } - types.push_str("PAGER") - } - if telephone.text_phone { - if types.is_empty() { - types.push(','); - } - types.push_str("TEXTPHONE") - } - - match self.vcard_data.get_mut() { - Some(vcard_builder) => *vcard_builder = vcard_builder.with_tel( - parameters!("TYPE" => types), - telephone.number, - ), - None => (), - };
\ No newline at end of file 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(), - ); } |