diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-03 07:08:49 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-03 07:08:49 +0100 |
commit | 51bf8e89ce07864b70d7138bbc3958faf499cc67 (patch) | |
tree | 31e870adb0bcd539135059613e05a0f31e08e987 /src/view/telephone.rs | |
parent | 94a0e361e180223adf2bc9760c8810dfa3c2681f (diff) | |
download | wasm-card-51bf8e89ce07864b70d7138bbc3958faf499cc67.tar.gz wasm-card-51bf8e89ce07864b70d7138bbc3958faf499cc67.tar.bz2 |
now it compiles
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(); |