From 036a567bae8346eb38f9237f59645dbcc4f1cd8c Mon Sep 17 00:00:00 2001 From: jelemux Date: Tue, 9 Feb 2021 23:18:45 +0100 Subject: switch to cargo-make; format files with rustfmt --- src/viewmodel/mod.rs | 103 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 43 deletions(-) (limited to 'src/viewmodel/mod.rs') diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs index 044dbad..0385c61 100644 --- a/src/viewmodel/mod.rs +++ b/src/viewmodel/mod.rs @@ -1,23 +1,24 @@ +use crate::view::VCardPropertyInputComponent; +use crate::viewmodel::utility::File; use wasm_bindgen::closure::Closure; -use web_sys::FileReader; use wasm_bindgen::JsCast; -use yew::services::ConsoleService; -use crate::viewmodel::utility::File; +use web_sys::FileReader; use yew::prelude::*; -use crate::view::VCardPropertyInputComponent; +use yew::services::ConsoleService; -pub mod vcard; -pub mod utility; pub mod address; -pub mod name; -pub mod telephone; pub mod dates; +pub mod name; pub mod organizational; - +pub mod telephone; +pub mod utility; +pub mod vcard; /// Trait for types that represent the data of a vcard property used inside of a `VCardPropertyInputComponent`. -pub trait VCardPropertyInputObject>: Clone + PartialEq - where Self: Sized +pub trait VCardPropertyInputObject>: + Clone + PartialEq +where + Self: Sized, { /// Function for creating a new (and empty) `VCardPropertyInputObject`. fn new() -> Self; @@ -25,12 +26,12 @@ pub trait VCardPropertyInputObject>: Clone fn get_input_fields(&self, link: &ComponentLink) -> Vec; /// Returns a `Html` representation of the `VCardPropertyInputObject`. fn render(&self, link: &ComponentLink) -> Html { - html!{ + html! {
- { + { for self.get_input_fields(link).iter().map(|field| field.render() - ) + ) }
} @@ -40,9 +41,9 @@ pub trait VCardPropertyInputObject>: Clone } /// Type for saving error messages. -/// +/// /// More of a placeholder for something better later on. -#[derive(Debug,Clone,PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub struct Error { pub msg: String, } @@ -97,10 +98,16 @@ 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, typ: &str) -> Html { - html!{ -
} } - /// Returns an `Html` representation of a file input field with the given parameters. - fn file_field_input(label: &str, name: &str, callback: &Callback>, file: &Option) -> Html { + /// Returns an `Html` representation of a file input field with the given parameters. + fn file_field_input( + label: &str, + name: &str, + callback: &Callback>, + file: &Option, + ) -> Html { let callback = callback.clone(); let onchange = Callback::<()>::default(); - let onchange = onchange.reform(move |c: ChangeData| + let onchange = onchange.reform(move |c: ChangeData| { if let ChangeData::Files(files) = c { match files.item(0) { - Some(file) => { + Some(file) => { let file_reader = FileReader::new().unwrap(); match file_reader.read_as_data_url(&file) { Ok(_) => (), @@ -131,33 +143,33 @@ impl VCardPropertyInputField { }; let callback = callback.clone(); - let onload = Closure::wrap(Box::new(move |event: Event|{ - let file_reader: FileReader = event.target().unwrap().dyn_into().unwrap(); - let data_url: Option = file_reader.result().unwrap().as_string(); + let onload = Closure::wrap(Box::new(move |event: Event| { + let file_reader: FileReader = + event.target().unwrap().dyn_into().unwrap(); + let data_url: Option = + file_reader.result().unwrap().as_string(); match data_url { - Some(content) => callback.emit( - Some(File { - name: file.name(), - content, - }) - ), + Some(content) => callback.emit(Some(File { + name: file.name(), + content, + })), None => { ConsoleService::warn("Couldn't get data url as string."); callback.emit(None); - }, + } }; }) as Box); file_reader.set_onload(Some(onload.as_ref().unchecked_ref())); onload.forget(); - }, + } None => callback.emit(None), } } else { callback.emit(None); } - ); - html!{ + }); + html! {
, + checked: &bool, + onclick: &Callback, + ) -> Html { + html! { +
} } -} \ No newline at end of file +} -- cgit v1.2.3