diff options
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/view/main.rs | 71 | ||||
-rw-r--r-- | src/view/property_group.rs | 11 |
3 files changed, 61 insertions, 23 deletions
@@ -1,4 +1,4 @@ -#![recursion_limit = "1024"] +#![recursion_limit = "2048"] extern crate console_error_panic_hook; extern crate wee_alloc; use std::panic; diff --git a/src/view/main.rs b/src/view/main.rs index d2d313a..dd32e33 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -47,10 +47,15 @@ pub struct MainView { pub enum Msg { AddName, + DelName(usize), AddAddress, + DelAddress(usize), AddTelephone, + DelTelephone(usize), AddOtherIdentification, + DelOtherIdentification(usize), AddOrganizational, + DelOrganizational(usize), ChangeDownloadOption(DownloadOption), @@ -87,34 +92,53 @@ impl Component for MainView { } fn update(&mut self, msg: Self::Message) -> ShouldRender { - let shouldrender; // let the compiler check if it is always set self.error = None; - match msg { + let shouldrender = match msg { Msg::AddName => { self.name_links.push(WeakComponentLink::default()); - shouldrender = true; + true + } + Msg::DelName(idx) => { + self.name_links.remove(idx); + true } Msg::AddAddress => { self.address_links.push(WeakComponentLink::default()); - shouldrender = true; + true + } + Msg::DelAddress(idx) => { + self.address_links.remove(idx); + true } Msg::AddTelephone => { self.telephone_links.push(WeakComponentLink::default()); - shouldrender = true; + true + } + Msg::DelTelephone(idx) => { + self.telephone_links.remove(idx); + true } Msg::AddOtherIdentification => { self.other_identifications_links .push(WeakComponentLink::default()); - shouldrender = true; + true + } + Msg::DelOtherIdentification(idx) => { + self.other_identifications_links.remove(idx); + true } Msg::AddOrganizational => { self.organizational_links.push(WeakComponentLink::default()); - shouldrender = true; + true + } + Msg::DelOrganizational(idx) => { + self.organizational_links.remove(idx); + true } Msg::ChangeDownloadOption(option) => { self.selected_option = option; - shouldrender = false; + false } Msg::Generate => { if self.selected_option == DownloadOption::VCard @@ -161,7 +185,7 @@ impl Component for MainView { } */ - shouldrender = true; + true } Msg::GeneratedName(name) => { self.answer_count += 1; @@ -173,7 +197,7 @@ impl Component for MainView { ), }; - shouldrender = true; + true } Msg::GeneratedOtherIdentification(other_identification) => { self.answer_count += 1; @@ -185,7 +209,7 @@ impl Component for MainView { ), }; - shouldrender = true; + true } Msg::GeneratedAddress(address) => { self.answer_count += 1; @@ -197,7 +221,7 @@ impl Component for MainView { ), }; - shouldrender = true; + true } Msg::GeneratedTelephone(telephone) => { self.answer_count += 1; @@ -209,7 +233,7 @@ impl Component for MainView { ), }; - shouldrender = true; + true } Msg::GeneratedOrganizational(organizational) => { self.answer_count += 1; @@ -219,7 +243,7 @@ impl Component for MainView { None => ConsoleService::info("Error in GeneratedOrganizational: Couldn't get mutable borrow of VCardData"), }; - shouldrender = true; + true } Msg::GenerationComplete => { self.answer_count = 0; @@ -443,9 +467,9 @@ impl Component for MainView { None => ConsoleService::info("Couldn't reset VCardData"), }; - shouldrender = true; + true } - Msg::Nope => shouldrender = false, + Msg::Nope => false }; if self.answer_count >= self.get_subcomponent_count() { @@ -502,13 +526,14 @@ impl Component for MainView { </div> { - for self.name_links.iter().map(|link| + for self.name_links.iter().enumerate().map(move |(idx, link)| html!{ <NameView weak_link=link generated=self.link.callback( |n: Name| Msg::GeneratedName(n) ) + delete=self.link.callback(move |_| Msg::DelName(idx)) /> } ) @@ -526,13 +551,14 @@ impl Component for MainView { </div> { - for self.other_identifications_links.iter().map(|link| + for self.other_identifications_links.iter().enumerate().map(move |(idx, link)| html!{ <OtherIdentificationView weak_link=link generated=self.link.callback( |d: OtherIdentification| Msg::GeneratedOtherIdentification(d) ) + delete=self.link.callback(move |_| Msg::DelOtherIdentification(idx)) /> } ) @@ -550,13 +576,14 @@ impl Component for MainView { </div> { - for self.address_links.iter().map(|link| + for self.address_links.iter().enumerate().map(move |(idx, link)| html!{ <AddressView weak_link=link generated=self.link.callback( |a: Address| Msg::GeneratedAddress(a) ) + delete=self.link.callback(move |_| Msg::DelAddress(idx)) /> } ) @@ -574,13 +601,14 @@ impl Component for MainView { </div> { - for self.telephone_links.iter().map(|link| + for self.telephone_links.iter().enumerate().map(move |(idx, link)| html!{ <TelephoneView weak_link=link generated=self.link.callback( |t: Telephone| Msg::GeneratedTelephone(t) ) + delete=self.link.callback(move |_| Msg::DelTelephone(idx)) /> } ) @@ -598,13 +626,14 @@ impl Component for MainView { </div> { - for self.organizational_links.iter().map(|link| + for self.organizational_links.iter().enumerate().map(move |(idx, link)| html!{ <OrganizationalView weak_link=link generated=self.link.callback( |o: Organizational| Msg::GeneratedOrganizational(o) ) + delete=self.link.callback(move |_| Msg::DelOrganizational(idx)) /> } ) diff --git a/src/view/property_group.rs b/src/view/property_group.rs index f4b62a4..1905cac 100644 --- a/src/view/property_group.rs +++ b/src/view/property_group.rs @@ -9,6 +9,7 @@ pub struct InputProps< M: 'static + PartialEq + Clone, > { pub generated: Callback<O>, + pub delete: Callback<()>, pub weak_link: WeakComponentLink<PropertyGroupInputComponent<O, M>>, } @@ -43,12 +44,20 @@ impl<O: 'static + VCardPropertyInputGroupObject<M>, M: 'static + PartialEq + Clo } fn view(&self) -> yew::virtual_dom::VNode { let link = self.props.weak_link.borrow().clone().unwrap(); + let delete = self.props.delete.clone(); html! { <div class="box"> { self.render_error() } - <h3 class="subtitle">{ self.value.get_title() }</h3> + <div class="level"> + <div class="level-left"> + <h3 class="subtitle">{ self.value.get_title() }</h3> + </div> + <div class="level-right"> + <button onclick=Callback::once(move |_| delete.emit(())) class="delete"></button> + </div> + </div> { self.value.render(&link) } |