From ac31460bac3c050abe1e45ec975f3537d1937751 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 18 Feb 2021 19:55:42 +0100 Subject: add delete buttons --- src/lib.rs | 2 +- src/view/main.rs | 71 ++++++++++++++++++++++++++++++++-------------- src/view/property_group.rs | 11 ++++++- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b5ad040..3504f73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { { - for self.name_links.iter().map(|link| + for self.name_links.iter().enumerate().map(move |(idx, link)| html!{ } ) @@ -526,13 +551,14 @@ impl Component for MainView { { - for self.other_identifications_links.iter().map(|link| + for self.other_identifications_links.iter().enumerate().map(move |(idx, link)| html!{ } ) @@ -550,13 +576,14 @@ impl Component for MainView { { - for self.address_links.iter().map(|link| + for self.address_links.iter().enumerate().map(move |(idx, link)| html!{ } ) @@ -574,13 +601,14 @@ impl Component for MainView { { - for self.telephone_links.iter().map(|link| + for self.telephone_links.iter().enumerate().map(move |(idx, link)| html!{ } ) @@ -598,13 +626,14 @@ impl Component for MainView { { - for self.organizational_links.iter().map(|link| + for self.organizational_links.iter().enumerate().map(move |(idx, link)| html!{ } ) 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, + pub delete: Callback<()>, pub weak_link: WeakComponentLink>, } @@ -43,12 +44,20 @@ impl, 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! {
{ self.render_error() } -

{ self.value.get_title() }

+
+
+

{ self.value.get_title() }

+
+
+ +
+
{ self.value.render(&link) } -- cgit v1.2.3