summaryrefslogtreecommitdiff
path: root/src/view/name.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-02-03 07:08:49 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-02-03 07:08:49 +0100
commit51bf8e89ce07864b70d7138bbc3958faf499cc67 (patch)
tree31e870adb0bcd539135059613e05a0f31e08e987 /src/view/name.rs
parent94a0e361e180223adf2bc9760c8810dfa3c2681f (diff)
downloadwasm-card-51bf8e89ce07864b70d7138bbc3958faf499cc67.tar.gz
wasm-card-51bf8e89ce07864b70d7138bbc3958faf499cc67.tar.bz2
now it compiles
Diffstat (limited to 'src/view/name.rs')
-rw-r--r--src/view/name.rs57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/view/name.rs b/src/view/name.rs
index bee9256..5b64bae 100644
--- a/src/view/name.rs
+++ b/src/view/name.rs
@@ -1,14 +1,17 @@
+use yew::services::ConsoleService;
+use yewtil::ptr::Irc;
+use yewtil::ptr::Mrc;
use crate::viewmodel::Error;
use crate::view::WeakComponentLink;
use yew::prelude::*;
-use vobject::Property;
+use yewtil::NeqAssign;
use crate::viewmodel::name::*;
use crate::viewmodel::VCardPropertyInputObject;
use super::VCardPropertyInputComponent;
pub struct NameView {
props: Props,
- value: Name,
+ value: Mrc<Name>,
error: Option<Error>,
}
@@ -24,14 +27,19 @@ pub enum Msg {
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
- pub generated_name: Callback<Name>,
- pub generated_fn: Callback<String>,
+ pub generated: Callback<Irc<Name>>,
pub weak_link: WeakComponentLink<NameView>,
}
impl VCardPropertyInputComponent<Name> for NameView {
fn get_input_object(&self) -> Name {
- self.value.clone()
+ match self.value.clone().try_unwrap() {
+ Ok(name) => name,
+ Err(_) => {
+ ConsoleService::error("Couldn't unwrap name");
+ Name::new()
+ },
+ }
}
fn get_title(&self) -> String {
"Name".to_string()
@@ -48,31 +56,40 @@ impl Component for NameView {
props.weak_link.borrow_mut().replace(link);
Self {
props,
- value: Name::new(),
+ value: Mrc::new(Name::new()),
error: None,
}
}
fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool {
match msg {
- Msg::UpdatePrefix(p) => self.value.prefix = p,
- Msg::UpdateFirstName(f) => self.value.first_name = f,
- Msg::UpdateMiddleName(m) => self.value.middle_name = m,
- Msg::UpdateLastName(l) => self.value.last_name = l,
- Msg::UpdateSuffix(s) => self.value.suffix = s,
- Generate => {
- self.props.generated_fn.emit(self.value.generate_fn());
- self.props.generated_name.emit(self.value);
+ Msg::UpdatePrefix(p) => match self.value.get_mut() {
+ Some(value) => value.prefix = p,
+ None => ConsoleService::info("Couldn't get mutable reference to name"),
+ },
+ Msg::UpdateFirstName(f) => match self.value.get_mut() {
+ Some(value) => value.first_name = f,
+ None => ConsoleService::info("Couldn't get mutable reference to name"),
+ },
+ Msg::UpdateMiddleName(m) => match self.value.get_mut() {
+ Some(value) => value.middle_name = m,
+ None => ConsoleService::info("Couldn't get mutable reference to name"),
+ },
+ Msg::UpdateLastName(l) => match self.value.get_mut() {
+ Some(value) => value.last_name = l,
+ None => ConsoleService::info("Couldn't get mutable reference to name"),
+ },
+ Msg::UpdateSuffix(s) => match self.value.get_mut() {
+ Some(value) => value.suffix = s,
+ None => ConsoleService::info("Couldn't get mutable reference to name"),
+ },
+ Msg::Generate => {
+ self.props.generated.emit(self.value.irc());
},
};
true
}
fn change(&mut self, props: <Self as yew::Component>::Properties) -> bool {
- if self.props != props {
- self.props = props;
- true
- } else {
- false
- }
+ self.props.neq_assign(props)
}
fn view(&self) -> yew::virtual_dom::VNode {
let link = self.props.weak_link.borrow().clone().unwrap();