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/view/main.rs | 71 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 21 deletions(-) (limited to 'src/view/main.rs') 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!{ } ) -- cgit v1.2.3