From 69ceb1f9ec68e41029759a6fcff3168adb6df373 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 4 Feb 2021 13:30:15 +0100 Subject: minor refactoring + comments --- src/viewmodel/mod.rs | 15 ++++++++++++++- src/viewmodel/name.rs | 17 ++++++++++++++++- src/viewmodel/vcard.rs | 9 +++++---- 3 files changed, 35 insertions(+), 6 deletions(-) (limited to 'src/viewmodel') diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs index de433de..d5d0de3 100644 --- a/src/viewmodel/mod.rs +++ b/src/viewmodel/mod.rs @@ -7,11 +7,16 @@ pub mod name; pub mod telephone; pub mod utility; + +/// Trait for types that represent the data of a vcard property used inside of a `VCardPropertyInputComponent`. pub trait VCardPropertyInputObject> - where Self: Sized + where Self: Sized { + /// Function for creating a new (and empty) `VCardPropertyInputObject`. fn new() -> Self; + /// Converts each field of the `VCardPropertyInputObject` to a VCardPropertyInputField and returns them as a vector. fn get_input_fields(&self, link: &ComponentLink) -> Vec; + /// Returns a `Html` representation of the `VCardPropertyInputObject`. fn render(&self, link: &ComponentLink) -> Html { html!{
@@ -23,14 +28,19 @@ pub trait VCardPropertyInputObject>
} } + /// Convenience function for checking if the `VCardPropertyInputObject` is empty. fn is_empty(&self) -> bool; } +/// Type for saving error messages. +/// +/// More of a placeholder for something better later on. #[derive(Debug,Clone,PartialEq)] pub struct Error { pub msg: String, } +/// Type that represents the visiual appearance of an input field. pub enum VCardPropertyInputField { Text { label: String, @@ -48,6 +58,7 @@ pub enum VCardPropertyInputField { } impl VCardPropertyInputField { + /// Returns a `Html` representation of the `VCardPropertyInputField`. pub fn render(&self) -> Html { match self { Self::Text { @@ -65,6 +76,7 @@ impl VCardPropertyInputField { } => Self::checkbox_field_input(label, id, value, onclick), } } + /// Returns an `Html` representation of a text input field with the given parameters. fn text_field_input(label: &str, id: &Option, placeholder: &Option, oninput: &Callback) -> Html { html!{
>, @@ -11,7 +12,7 @@ pub struct VCardData { } macro_rules! make_vec_adder_fn { - ( $fnname:ident $property:ident $($arg_name:ident : $arg_type:ty),* ) => { + ( 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);)* } @@ -26,7 +27,7 @@ impl VCardData { telephones: Vec::new(), } } - make_vec_adder_fn!( add_name names name: Irc ); - make_vec_adder_fn!( add_address addresses address: Irc
); - make_vec_adder_fn!( add_telephone telephones telephone: Irc ); + make_vec_adder_fn!( fn add_name names => name: Irc ); + make_vec_adder_fn!( fn add_address addresses => address: Irc
); + make_vec_adder_fn!( fn add_telephone telephones => telephone: Irc ); } \ No newline at end of file -- cgit v1.2.3