summaryrefslogtreecommitdiff
path: root/src/view/name.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/name.rs')
-rw-r--r--src/view/name.rs138
1 files changed, 24 insertions, 114 deletions
diff --git a/src/view/name.rs b/src/view/name.rs
index 872676c..4ac78a4 100644
--- a/src/view/name.rs
+++ b/src/view/name.rs
@@ -1,86 +1,14 @@
use yew::prelude::*;
use vcard::properties;
-use vcard::values::{self, text};
-
-use crate::util;
-
-#[derive(Clone)]
-pub struct Name {
- pub prefix: String,
- pub first_name: String,
- pub middle_name: String,
- pub last_name: String,
- pub suffix: String,
-}
-
-impl Name {
- pub fn new() -> Self {
- Self {
- prefix: String::new(),
- first_name: String::new(),
- middle_name: String::new(),
- last_name: String::new(),
- suffix: String::new(),
- }
- }
- pub fn formatted_name(&self) -> String {
- let mut formatted_name = String::new();
-
- if !self.prefix.is_empty() {
- formatted_name.push_str(&self.prefix);
- }
- if !self.first_name.is_empty() {
- formatted_name.push_str(" ");
- formatted_name.push_str(&self.first_name);
- }
- if !self.middle_name.is_empty() {
- formatted_name.push_str(" ");
- formatted_name.push_str(&self.middle_name);
- }
- if !self.last_name.is_empty() {
- formatted_name.push_str(" ");
- formatted_name.push_str(&self.last_name);
- }
- if !self.suffix.is_empty() {
- formatted_name.push_str(", ");
- formatted_name.push_str(&self.suffix);
- }
-
- formatted_name
- }
- pub fn to_vcard_value(&self) -> properties::Name {
- let name_value = values::name_value::NameValue::from_components(
- match self.last_name.is_empty() {
- true => None,
- false => Some(text::Component::from_str(&self.last_name).unwrap()),
- },
- match self.first_name.is_empty() {
- true => None,
- false => Some(text::Component::from_str(&self.first_name).unwrap()),
- },
- match self.middle_name.is_empty() {
- true => None,
- false => Some(text::Component::from_str(&self.middle_name).unwrap()),
- },
- match self.prefix.is_empty() {
- true => None,
- false => Some(text::Component::from_str(&self.prefix).unwrap()),
- },
- match self.suffix.is_empty() {
- true => None,
- false => Some(text::Component::from_str(&self.suffix).unwrap()),
- },
- );
-
- properties::Name::from_name_value(name_value)
- }
-}
+use super::input_objects::name::*;
+use super::input_objects::VCardPropertyInputObject;
+use super::VCardPropertyInputComponent;
pub struct NameView {
link: ComponentLink<Self>,
value: Name,
oninput: Callback<Name>,
- //errors: Vec<String>,
+ errors: Vec<String>,
}
pub enum Msg {
@@ -94,7 +22,18 @@ pub enum Msg {
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
pub oninput: Callback<Name>,
- //pub errors: Vec<String>,
+}
+
+impl VCardPropertyInputComponent<properties::Name, Name> for NameView {
+ fn get_input_object(&self) -> Name {
+ self.value.clone()
+ }
+ fn get_title(&self) -> String {
+ "Name".to_string()
+ }
+ fn get_errors(&self) -> Vec<String> {
+ self.errors.clone()
+ }
}
impl Component for NameView {
@@ -105,6 +44,7 @@ impl Component for NameView {
link,
value: Name::new(),
oninput: props.oninput,
+ errors: vec![],
}
}
fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool {
@@ -125,46 +65,16 @@ impl Component for NameView {
fn view(&self) -> yew::virtual_dom::VNode {
html!{
<div class="box">
- <h3 class="subtitle">{ "Name" }</h3>
-
- <div class="columns is-mobile is-multiline">
-
- { util::text_field_input(
- "Prefix",
- "prefix",
- Some("Sir"),
- self.link.callback(|e: InputData| Msg::UpdatePrefix(e.value))
- ) }
-
- { util::text_field_input(
- "First name",
- "first_name",
- Some("Arthur"),
- self.link.callback(|e: InputData| Msg::UpdateFirstName(e.value))
- ) }
-
- { util::text_field_input(
- "Middle name",
- "middle_name",
- Some("Charles"),
- self.link.callback(|e: InputData| Msg::UpdateMiddleName(e.value))
- ) }
+ {
+ self.render_errors()
+ }
- { util::text_field_input(
- "Last name",
- "last_name",
- Some("Clarke"),
- self.link.callback(|e: InputData| Msg::UpdateLastName(e.value))
- ) }
+ <h3 class="subtitle">{ self.get_title() }</h3>
- { util::text_field_input(
- "Suffix",
- "suffix",
- Some("CBE FRAS"),
- self.link.callback(|e: InputData| Msg::UpdateSuffix(e.value))
- ) }
+ {
+ self.get_input_object().render(&self.link)
+ }
- </div>
</div>
}
}