summaryrefslogtreecommitdiff
path: root/src/viewmodel
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-02-03 07:08:49 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-02-03 07:08:49 +0100
commit51bf8e89ce07864b70d7138bbc3958faf499cc67 (patch)
tree31e870adb0bcd539135059613e05a0f31e08e987 /src/viewmodel
parent94a0e361e180223adf2bc9760c8810dfa3c2681f (diff)
downloadwasm-card-51bf8e89ce07864b70d7138bbc3958faf499cc67.tar.gz
wasm-card-51bf8e89ce07864b70d7138bbc3958faf499cc67.tar.bz2
now it compiles
Diffstat (limited to 'src/viewmodel')
-rw-r--r--src/viewmodel/address.rs2
-rw-r--r--src/viewmodel/mod.rs2
-rw-r--r--src/viewmodel/name.rs4
-rw-r--r--src/viewmodel/telephone.rs15
-rw-r--r--src/viewmodel/vcard.rs32
5 files changed, 38 insertions, 17 deletions
diff --git a/src/viewmodel/address.rs b/src/viewmodel/address.rs
index 61bd464..6fd3173 100644
--- a/src/viewmodel/address.rs
+++ b/src/viewmodel/address.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::view::address::*;
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct Address {
pub post_office_box: String,
pub extension: String,
diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs
index cc25d68..de433de 100644
--- a/src/viewmodel/mod.rs
+++ b/src/viewmodel/mod.rs
@@ -1,7 +1,7 @@
use yew::prelude::*;
-use vobject::Property;
use crate::view::VCardPropertyInputComponent;
+pub mod vcard;
pub mod address;
pub mod name;
pub mod telephone;
diff --git a/src/viewmodel/name.rs b/src/viewmodel/name.rs
index 26beaa1..a88e07f 100644
--- a/src/viewmodel/name.rs
+++ b/src/viewmodel/name.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::view::name::*;
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct Name {
pub prefix: String,
pub first_name: String,
@@ -70,7 +70,7 @@ impl VCardPropertyInputObject<NameView> for Name {
impl Name {
pub fn generate_fn(&self) -> String {
- let full_name = String::new();
+ let mut full_name = String::new();
full_name.push_str(&self.prefix);
if !self.first_name.is_empty() {
diff --git a/src/viewmodel/telephone.rs b/src/viewmodel/telephone.rs
index e5f63f0..6c930a2 100644
--- a/src/viewmodel/telephone.rs
+++ b/src/viewmodel/telephone.rs
@@ -1,11 +1,9 @@
-use std::collections::HashSet;
use super::*;
use crate::view::telephone::*;
-#[derive(Clone)]
+#[derive(Clone, Debug)]
pub struct Telephone {
pub number: String,
- pub extension: String,
pub work: bool,
pub home: bool,
pub text: bool,
@@ -21,7 +19,6 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone {
fn new() -> Self {
Self {
number: String::new(),
- extension: String::new(),
work: false,
home: false,
text: false,
@@ -42,13 +39,6 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone {
oninput: link.callback(|e: InputData| Msg::UpdateNumber(e.value)),
value: self.number.clone(),
},
- VCardPropertyInputField::Text{
- label: "Extension".to_string(),
- id: Some("extension".to_string()),
- placeholder: None,
- oninput: link.callback(|e: InputData| Msg::UpdateExtension(e.value)),
- value: self.extension.clone(),
- },
VCardPropertyInputField::CheckBox{
label: "Work".to_string(),
id: Some("work".to_string()),
@@ -106,7 +96,6 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone {
]
}
fn is_empty(&self) -> bool {
- self.number.is_empty() &&
- self.extension.is_empty()
+ self.number.is_empty()
}
} \ No newline at end of file
diff --git a/src/viewmodel/vcard.rs b/src/viewmodel/vcard.rs
new file mode 100644
index 0000000..2d415b7
--- /dev/null
+++ b/src/viewmodel/vcard.rs
@@ -0,0 +1,32 @@
+use yewtil::ptr::Irc;
+use crate::viewmodel::telephone::Telephone;
+use crate::viewmodel::address::Address;
+use crate::viewmodel::name::Name;
+
+#[derive(Clone, Debug)]
+pub struct VCardData {
+ pub names: Vec<Irc<Name>>,
+ pub addresses: Vec<Irc<Address>>,
+ pub telephones: Vec<Irc<Telephone>>,
+}
+
+macro_rules! make_vec_adder_fn {
+ ( $fnname:ident $property:ident $($arg_name:ident : $arg_type:ty),* ) => {
+ pub fn $fnname(&mut self, $( $arg_name : $arg_type ),*) {
+ $(self.$property.push($arg_name);)*
+ }
+ };
+}
+
+impl VCardData {
+ pub fn new() -> Self {
+ Self {
+ names: Vec::new(),
+ addresses: Vec::new(),
+ telephones: Vec::new(),
+ }
+ }
+ make_vec_adder_fn!( add_name names name: Irc<Name> );
+ make_vec_adder_fn!( add_address addresses address: Irc<Address> );
+ make_vec_adder_fn!( add_telephone telephones telephone: Irc<Telephone> );
+} \ No newline at end of file