From 51bf8e89ce07864b70d7138bbc3958faf499cc67 Mon Sep 17 00:00:00 2001 From: jelemux Date: Wed, 3 Feb 2021 07:08:49 +0100 Subject: now it compiles --- src/view/name.rs | 57 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'src/view/name.rs') 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, error: Option, } @@ -24,14 +27,19 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated_name: Callback, - pub generated_fn: Callback, + pub generated: Callback>, pub weak_link: WeakComponentLink, } impl VCardPropertyInputComponent 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: ::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: ::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(); -- cgit v1.2.3