From 3f0892368bcf475fdae39f24ef51b82b3013535f Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 28 Jan 2021 17:41:49 +0100 Subject: try to fix problem with vcard mutable references --- src/view/mod.rs | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/view/mod.rs') diff --git a/src/view/mod.rs b/src/view/mod.rs index b47612a..f208c44 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -1,4 +1,7 @@ use yew::prelude::*; +use std::cell::RefCell; +use std::ops::Deref; +use std::rc::Rc; use crate::viewmodel::*; pub mod main; @@ -12,20 +15,50 @@ pub trait VCardPropertyInputComponent: Component { fn get_input_object(&self) -> T; fn get_title(&self) -> String; - fn get_errors(&self) -> Vec; - fn render_errors(&self) -> Html { + fn get_error(&self) -> Option; + fn render_error(&self) -> Html { html!{ <> { - for self.get_errors().iter().map(|err| + if self.get_error().is_some() { html!{
- { err } + { self.get_error().unwrap().msg }
} - ) + } else { + html!{} + } } } } +} + +pub struct WeakComponentLink(Rc>>>); + +impl Clone for WeakComponentLink { + fn clone(&self) -> Self { + Self(Rc::clone(&self.0)) + } +} + +impl Default for WeakComponentLink { + fn default() -> Self { + Self(Rc::default()) + } +} + +impl Deref for WeakComponentLink { + type Target = Rc>>>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl PartialEq for WeakComponentLink { + fn eq(&self, other: &Self) -> bool { + Rc::ptr_eq(&self.0, &other.0) + } } \ No newline at end of file -- cgit v1.2.3