summaryrefslogtreecommitdiff
path: root/src/view/mod.rs
blob: f208c4490e26b736ac1778673ccb1c672e573175 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use yew::prelude::*;
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::Rc;
use crate::viewmodel::*;

pub mod main;
pub mod name;
pub mod address;
pub mod telephone;

pub trait VCardPropertyInputComponent<P, T>: Component 
    where   P: vcard::properties::Property,
            T: VCardPropertyInputObject<P, Self>
{
    fn get_input_object(&self) -> T;
    fn get_title(&self) -> String;
    fn get_error(&self) -> Option<Error>;
    fn render_error(&self) -> Html {
        html!{
            <>
                {
                    if self.get_error().is_some() {
                        html!{
                            <div class="notification is-danger is-light">
                                { 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)
    }
}