summaryrefslogtreecommitdiff
path: root/src/view/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/main.rs')
-rw-r--r--src/view/main.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/view/main.rs b/src/view/main.rs
index 83acc3f..0d2cddb 100644
--- a/src/view/main.rs
+++ b/src/view/main.rs
@@ -1,3 +1,4 @@
+use crate::viewmodel::dates::Dates;
use yew::services::ConsoleService;
use crate::viewmodel::vcard::VCardData;
use crate::viewmodel::Error;
@@ -6,6 +7,7 @@ use crate::viewmodel::VCardPropertyInputObject;
use super::WeakComponentLink;
use super::name::{self,NameView};
use super::address::{self,AddressView};
+use super::dates::{self,DatesView};
use genpdf::Element as _;
use genpdf::{elements, style, fonts};
use qrcodegen::QrCode;
@@ -32,6 +34,7 @@ pub struct MainView {
name_links: Vec<WeakComponentLink<NameView>>,
address_links: Vec<WeakComponentLink<AddressView>>,
telephone_links: Vec<WeakComponentLink<TelephoneView>>,
+ dates_links: Vec<WeakComponentLink<DatesView>>,
answer_count: usize,
}
@@ -40,6 +43,7 @@ pub enum Msg {
AddName,
AddAddress,
AddTelephone,
+ AddDates,
ChangeDownloadOption(DownloadOption),
@@ -47,6 +51,7 @@ pub enum Msg {
GeneratedName(Name),
GeneratedAddress(Address),
GeneratedTelephone(Telephone),
+ GeneratedDates(Dates),
GenerationComplete,
Nope,
@@ -67,6 +72,7 @@ impl Component for MainView {
name_links: vec![WeakComponentLink::default()],
address_links: vec![WeakComponentLink::default()],
telephone_links: vec![WeakComponentLink::default()],
+ dates_links: vec![WeakComponentLink::default()],
answer_count: 0,
}
}
@@ -88,6 +94,10 @@ impl Component for MainView {
self.telephone_links.push(WeakComponentLink::default());
shouldrender = true;
},
+ Msg::AddDates => {
+ self.dates_links.push(WeakComponentLink::default());
+ shouldrender = true;
+ },
Msg::ChangeDownloadOption(option) => {
self.selected_option = option;
shouldrender = false;
@@ -110,6 +120,11 @@ impl Component for MainView {
let telephone_link = telephone_link.borrow().clone().unwrap();
telephone_link.send_message(telephone::Msg::Generate);
}
+
+ for dates_link in self.dates_links.iter() {
+ let dates_link = dates_link.borrow().clone().unwrap();
+ dates_link.send_message(dates::Msg::Generate)
+ }
}
/*
DownloadOption::PDF => {
@@ -163,6 +178,17 @@ impl Component for MainView {
shouldrender = true;
},
+ Msg::GeneratedDates(dates) => {
+
+ self.answer_count += 1;
+
+ match self.vcard_data.get_mut() {
+ Some(vcard_data) => vcard_data.add_dates(dates),
+ None => ConsoleService::info("Error in GeneratedDates: Couldn't get mutable borrow of VCardData"),
+ };
+
+ shouldrender = true;
+ },
Msg::GenerationComplete => {
self.answer_count = 0;
@@ -305,6 +331,20 @@ impl Component for MainView {
);
}
}
+
+ for dates in vcard_data.datess {
+
+ if !dates.anniversary.is_empty() {
+ builder = builder.with_anniversary(dates.anniversary);
+ }
+
+ if !dates.birthday.is_empty() {
+ builder = builder.with_bday(
+ parameters!(),
+ dates.birthday
+ );
+ }
+ }
let rev = Local::now();
@@ -445,6 +485,19 @@ impl Component for MainView {
)
}
+ {
+ for self.dates_links.iter().map(|link|
+ html!{
+ <DatesView weak_link=link
+ generated=self.link.callback(
+ |d: Dates|
+ Msg::GeneratedDates(d)
+ )
+ />
+ }
+ )
+ }
+
<div class="block level-left">
<button onclick=self.link.callback(|_| Msg::Generate) class="button is-primary level-item">{ "Generate" }</button>
@@ -587,5 +640,6 @@ impl MainView {
self.name_links.len()
+ self.address_links.len()
+ self.telephone_links.len()
+ + self.dates_links.len()
}
} \ No newline at end of file