diff options
Diffstat (limited to 'src/view/telephone.rs')
-rw-r--r-- | src/view/telephone.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/view/telephone.rs b/src/view/telephone.rs index 26d7806..ca58538 100644 --- a/src/view/telephone.rs +++ b/src/view/telephone.rs @@ -1,19 +1,22 @@ +use yew::services::ConsoleService; +use yewtil::ptr::Irc; +use yewtil::ptr::Mrc; use crate::view::WeakComponentLink; use crate::viewmodel::Error; use yew::prelude::*; +use yewtil::NeqAssign; use crate::viewmodel::telephone::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; pub struct TelephoneView { props: Props, - value: Telephone, + value: Mrc<Telephone>, error: Option<Error>, } pub enum Msg { UpdateNumber(String), - UpdateExtension(String), ToggleWork, ToggleHome, ToggleText, @@ -29,13 +32,19 @@ pub enum Msg { #[derive(Clone, PartialEq, Properties)] pub struct Props { - pub generated: Callback<Telephone>, + pub generated: Callback<Irc<Telephone>>, pub weak_link: WeakComponentLink<TelephoneView>, } impl VCardPropertyInputComponent<Telephone> for TelephoneView { fn get_input_object(&self) -> Telephone { - self.value.clone() + match self.value.irc().try_unwrap() { + Ok(telephone) => telephone, + Err(_) => { + ConsoleService::error("Couldn't unwrap telephone"); + Telephone::new() + }, + } } fn get_title(&self) -> String { "Telephone".to_string() @@ -52,14 +61,13 @@ impl Component for TelephoneView { props.weak_link.borrow_mut().replace(link); Self { props, - value: Telephone::new(), + value: Mrc::new(Telephone::new()), error: None, } } fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool { match msg { Msg::UpdateNumber(n) => self.value.number = n, - Msg::UpdateExtension(e) => self.value.extension = e, Msg::ToggleWork => self.value.work = !self.value.work, Msg::ToggleHome => self.value.home = !self.value.home, Msg::ToggleText => self.value.text = !self.value.text, @@ -70,18 +78,13 @@ impl Component for TelephoneView { Msg::TogglePager => self.value.pager = !self.value.pager, Msg::ToggleTextPhone => self.value.text_phone = !self.value.text_phone, Msg::Generate => { - self.props.generated.emit(self.value); + 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(); |