summaryrefslogtreecommitdiff
path: root/src/view/mod.rs
diff options
context:
space:
mode:
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