diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-09 23:18:45 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-09 23:18:45 +0100 |
commit | 036a567bae8346eb38f9237f59645dbcc4f1cd8c (patch) | |
tree | 21a86e3c5cb8964030c414718190af12f3d26125 /src/viewmodel/mod.rs | |
parent | 9df3ff8d633a18e934d4e62b0e2e718620760552 (diff) | |
download | wasm-card-036a567bae8346eb38f9237f59645dbcc4f1cd8c.tar.gz wasm-card-036a567bae8346eb38f9237f59645dbcc4f1cd8c.tar.bz2 |
switch to cargo-make; format files with rustfmt
Diffstat (limited to 'src/viewmodel/mod.rs')
-rw-r--r-- | src/viewmodel/mod.rs | 103 |
1 files changed, 60 insertions, 43 deletions
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<C: VCardPropertyInputComponent<Self>>: Clone + PartialEq - where Self: Sized +pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: + Clone + PartialEq +where + Self: Sized, { /// Function for creating a new (and empty) `VCardPropertyInputObject`. fn new() -> Self; @@ -25,12 +26,12 @@ pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: Clone fn get_input_fields(&self, link: &ComponentLink<C>) -> Vec<VCardPropertyInputField>; /// Returns a `Html` representation of the `VCardPropertyInputObject`. fn render(&self, link: &ComponentLink<C>) -> Html { - html!{ + html! { <div class="columns is-mobile is-multiline"> - { + { for self.get_input_fields(link).iter().map(|field| field.render() - ) + ) } </div> } @@ -40,9 +41,9 @@ pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: 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<String>, placeholder: &Option<String>, oninput: &Callback<InputData>, typ: &str) -> Html { - html!{ - <div class="field column + /// Returns an `Html` representation of a text input field with the given parameters. + fn text_field_input( + label: &str, + id: &Option<String>, + placeholder: &Option<String>, + oninput: &Callback<InputData>, + typ: &str, + ) -> Html { + html! { + <div class="field column is-one-fifth-widescreen is-one-quarter-desktop is-one-third-tablet @@ -116,14 +123,19 @@ impl VCardPropertyInputField { </div> } } - /// Returns an `Html` representation of a file input field with the given parameters. - fn file_field_input(label: &str, name: &str, callback: &Callback<Option<File>>, file: &Option<File>) -> Html { + /// Returns an `Html` representation of a file input field with the given parameters. + fn file_field_input( + label: &str, + name: &str, + callback: &Callback<Option<File>>, + file: &Option<File>, + ) -> 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<String> = 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<String> = + 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<dyn FnMut(_)>); file_reader.set_onload(Some(onload.as_ref().unchecked_ref())); onload.forget(); - }, + } None => callback.emit(None), } } else { callback.emit(None); } - ); - html!{ + }); + html! { <div class="field column is-one-fifth-widescreen is-one-quarter-desktop @@ -192,17 +204,22 @@ impl VCardPropertyInputField { </div> } } - /// Returns an `Html` representation of a checkbox input field with the given parameters. - fn checkbox_field_input(label: &str, id: &Option<String>, checked: &bool, onclick: &Callback<MouseEvent>) -> Html { - html!{ - <div class="field column + /// Returns an `Html` representation of a checkbox input field with the given parameters. + fn checkbox_field_input( + label: &str, + id: &Option<String>, + checked: &bool, + onclick: &Callback<MouseEvent>, + ) -> Html { + html! { + <div class="field column is-one-fifth-widescreen is-one-quarter-desktop is-one-third-tablet is-half-mobile" > <label class="checkbox"> <input id=id.as_ref().unwrap_or(&"".to_string()) - type="checkbox" + type="checkbox" checked=*checked onclick=onclick /> @@ -211,4 +228,4 @@ impl VCardPropertyInputField { </div> } } -}
\ No newline at end of file +} |