diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-11 12:07:22 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-11 12:07:22 +0100 |
commit | 0660151a8b641fa0a23dde2598132029970f7ae4 (patch) | |
tree | 0bdeb1108419add4570f278795f0bfd0f5366856 /src/model/dates.rs | |
parent | 036a567bae8346eb38f9237f59645dbcc4f1cd8c (diff) | |
download | wasm-card-0660151a8b641fa0a23dde2598132029970f7ae4.tar.gz wasm-card-0660151a8b641fa0a23dde2598132029970f7ae4.tar.bz2 |
refactoring - reduced code size by about a third
Diffstat (limited to 'src/model/dates.rs')
-rw-r--r-- | src/model/dates.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/model/dates.rs b/src/model/dates.rs new file mode 100644 index 0000000..192f986 --- /dev/null +++ b/src/model/dates.rs @@ -0,0 +1,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() + } +} |