1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
use super::*;
/// Type that represents the vcard `anniversary` and `birthday` properties.
#[derive(Clone, Debug, PartialEq)]
pub struct Dates {
pub anniversary: String,
pub birthday: String,
}
#[derive(Clone, PartialEq)]
pub enum DatesMsg {
UpdateAnniversary(String),
UpdateBirthday(String),
Generate,
}
impl VCardPropertyInputObject<DatesMsg> for Dates {
fn new() -> Self {
Self {
anniversary: String::new(),
birthday: String::new(),
}
}
fn get_title(&self) -> std::string::String {
"Dates".to_string()
}
fn get_input_fields(
&self,
link: &yew::html::Scope<PropertyGroupInputComponent<Self, DatesMsg>>,
) -> std::vec::Vec<VCardPropertyInputField> {
let typ = String::from("date");
vec![
VCardPropertyInputField::Text {
label: "Anniversary".to_string(),
id: Some("anniversary".to_string()),
placeholder: None,
oninput: link.callback(|e: InputData| DatesMsg::UpdateAnniversary(e.value)),
value: self.anniversary.clone(),
typ: typ.clone(),
},
VCardPropertyInputField::Text {
label: "Birthday".to_string(),
id: Some("birthday".to_string()),
placeholder: None,
oninput: link.callback(|e: InputData| DatesMsg::UpdateBirthday(e.value)),
value: self.birthday.clone(),
typ,
},
]
}
fn update(
&mut self,
props: InputProps<Self, DatesMsg>,
msg: <PropertyGroupInputComponent<Self, DatesMsg> as yew::Component>::Message,
) -> bool {
match msg {
DatesMsg::UpdateAnniversary(a) => self.anniversary = a,
DatesMsg::UpdateBirthday(b) => self.birthday = b,
DatesMsg::Generate => {
props.generated.emit(self.clone());
}
};
true
}
fn is_empty(&self) -> bool {
self.anniversary.is_empty() && self.birthday.is_empty()
}
}
|