summaryrefslogtreecommitdiff
path: root/src/view/mod.rs
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-01-28 17:41:49 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-01-28 17:41:49 +0100
commit3f0892368bcf475fdae39f24ef51b82b3013535f (patch)
tree087a0869e618cc37b48e6d462c99bc1b289ddabf /src/view/mod.rs
parent4a0c73eebb8dfd6a5543945049175f64b9817c96 (diff)
downloadwasm-card-3f0892368bcf475fdae39f24ef51b82b3013535f.tar.gz
wasm-card-3f0892368bcf475fdae39f24ef51b82b3013535f.tar.bz2
try to fix problem with vcard mutable references
Diffstat (limited to 'src/view/mod.rs')
-rw-r--r--src/view/mod.rs43
1 files changed, 38 insertions, 5 deletions
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<P, T>: Component
{
fn get_input_object(&self) -> T;
fn get_title(&self) -> String;
- fn get_errors(&self) -> Vec<String>;
- fn render_errors(&self) -> Html {
+ fn get_error(&self) -> Option<Error>;
+ fn render_error(&self) -> Html {
html!{
<>
{
- for self.get_errors().iter().map(|err|
+ if self.get_error().is_some() {
html!{
<div class="notification is-danger is-light">
- { err }
+ { self.get_error().unwrap().msg }
</div>
}
- )
+ } else {
+ html!{}
+ }
}
</>
}
}
+}
+
+pub struct WeakComponentLink<COMP: Component>(Rc<RefCell<Option<ComponentLink<COMP>>>>);
+
+impl<COMP: Component> Clone for WeakComponentLink<COMP> {
+ fn clone(&self) -> Self {
+ Self(Rc::clone(&self.0))
+ }
+}
+
+impl<COMP: Component> Default for WeakComponentLink<COMP> {
+ fn default() -> Self {
+ Self(Rc::default())
+ }
+}
+
+impl<COMP: Component> Deref for WeakComponentLink<COMP> {
+ type Target = Rc<RefCell<Option<ComponentLink<COMP>>>>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl<COMP: Component> PartialEq for WeakComponentLink<COMP> {
+ fn eq(&self, other: &Self) -> bool {
+ Rc::ptr_eq(&self.0, &other.0)
+ }
} \ No newline at end of file