summaryrefslogtreecommitdiff
path: root/src/view/main.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-02-18 19:55:42 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-02-18 19:55:42 +0100
commitac31460bac3c050abe1e45ec975f3537d1937751 (patch)
treec5e0da8354a2f276e0a584c166fd2e824d9aec3e /src/view/main.rs
parente85c3283d4ea5d5d2f0bb7e6cdd6c48ddb9a786b (diff)
downloadwasm-card-ac31460bac3c050abe1e45ec975f3537d1937751.tar.gz
wasm-card-ac31460bac3c050abe1e45ec975f3537d1937751.tar.bz2
add delete buttons
Diffstat (limited to 'src/view/main.rs')
-rw-r--r--src/view/main.rs71
1 files changed, 50 insertions, 21 deletions
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))
/>
}
)