summaryrefslogtreecommitdiff
path: root/src/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/view')
-rw-r--r--src/view/dates.rs78
-rw-r--r--src/view/main.rs54
-rw-r--r--src/view/mod.rs1
3 files changed, 133 insertions, 0 deletions
diff --git a/src/view/dates.rs b/src/view/dates.rs
new file mode 100644
index 0000000..1c16680
--- /dev/null
+++ b/src/view/dates.rs
@@ -0,0 +1,78 @@
+use yew::prelude::*;
+use yewtil::NeqAssign;
+use crate::viewmodel::Error;
+use crate::view::WeakComponentLink;
+use crate::viewmodel::dates::*;
+use crate::viewmodel::VCardPropertyInputObject;
+use super::VCardPropertyInputComponent;
+
+pub struct DatesView {
+ props: Props,
+ value: Dates,
+ error: Option<Error>,
+}
+
+pub enum Msg {
+ UpdateAnniversary(String),
+ UpdateBirthday(String),
+
+ Generate,
+}
+
+#[derive(Clone, PartialEq, Properties)]
+pub struct Props {
+ pub generated: Callback<Dates>,
+ pub weak_link: WeakComponentLink<DatesView>,
+}
+
+impl VCardPropertyInputComponent<Dates> for DatesView {
+ fn get_input_object(&self) -> Dates {
+ self.value.clone()
+ }
+ fn get_title(&self) -> std::string::String {
+ "Dates".to_string()
+ }
+ fn get_error(&self) -> std::option::Option<Error> {
+ self.error.clone()
+ }
+}
+
+impl Component for DatesView {
+ type Message = Msg;
+ type Properties = Props;
+ fn create(props: <Self as yew::Component>::Properties, link: yew::html::Scope<Self>) -> Self {
+ props.weak_link.borrow_mut().replace(link);
+ Self {
+ props,
+ value: Dates::new(),
+ error: None,
+ }
+ }
+ fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool {
+ match msg {
+ Msg::UpdateAnniversary(a) => self.value.anniversary = a,
+ Msg::UpdateBirthday(b) => self.value.birthday = b,
+ Msg::Generate => {
+ self.props.generated.emit(self.value.clone());
+ },
+ };
+ true
+ }
+ fn change(&mut self, props: <Self as yew::Component>::Properties) -> bool {
+ self.props.neq_assign(props)
+ }
+ fn view(&self) -> yew::virtual_dom::VNode {
+ let link = self.props.weak_link.borrow().clone().unwrap();
+
+ html!{
+ <div class="box">
+ { self.render_error() }
+
+ <h3 class="subtitle">{ self.get_title() }</h3>
+
+ { self.get_input_object().render(&link) }
+
+ </div>
+ }
+ }
+} \ No newline at end of file
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
diff --git a/src/view/mod.rs b/src/view/mod.rs
index d97c6e4..65ef06d 100644
--- a/src/view/mod.rs
+++ b/src/view/mod.rs
@@ -8,6 +8,7 @@ pub mod main;
pub mod name;
pub mod address;
pub mod telephone;
+pub mod dates;
/// Trait for types that represent an input component for a vcard property.
pub trait VCardPropertyInputComponent<T: VCardPropertyInputObject<Self>>: Component {