From e57afed1622a26f6cc470ffdca45c5530abd98dc Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 10 May 2023 12:25:23 -0400 Subject: [PATCH] Made room & bathroom textfields to dropdowns to simplify agent input --- src/pages/admin/fields/unit.rs | 115 ++++++++++++++++++++++++++------- src/pages/details.rs | 5 +- 2 files changed, 95 insertions(+), 25 deletions(-) diff --git a/src/pages/admin/fields/unit.rs b/src/pages/admin/fields/unit.rs index e8fb617..eaccfd8 100644 --- a/src/pages/admin/fields/unit.rs +++ b/src/pages/admin/fields/unit.rs @@ -55,6 +55,18 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { user_typed.set(true); }) }; + let onselect_cb_2 = { + let user_typed = user_typed.clone(); + Callback::from(move |_| { + user_typed.set(true); + }) + }; + let onselect_cb_3 = { + let user_typed = user_typed.clone(); + Callback::from(move |_| { + user_typed.set(true); + }) + }; let onchange_number_cb = { let user_typed = user_typed.clone(); Callback::from(move |_| { @@ -67,18 +79,12 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { user_typed.set(true); }) }; - let onchange_number_cb_3 = { - let user_typed = user_typed.clone(); - Callback::from(move |_| { - user_typed.set(true); - }) - }; // Fields let price_usd = use_state_eq(|| 0.0); let unit_type_handle: UseStateHandle> = use_state_eq(|| None); - let rooms_handle: UseStateHandle = use_state_eq(|| 0); - let bathrooms_handle: UseStateHandle = use_state_eq(|| 0.0); + let rooms_handle: UseStateHandle> = use_state_eq(|| None); + let bathrooms_handle: UseStateHandle> = use_state_eq(|| None); let area_handle: UseStateHandle = use_state_eq(|| 0.0); let media_handle: UseStateHandle = use_state_eq(|| MediaList { media_list: Vec::new(), @@ -102,12 +108,12 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { }, }); rooms_handle.set(match (*unit_opt).clone() { - Some(unit) => unit.rooms, - None => 0 + Some(unit) => Some(unit.rooms), + None => None }); bathrooms_handle.set(match (*unit_opt).clone() { - Some(unit) => unit.bathrooms, - None => 0.0 + Some(unit) => Some(unit.bathrooms), + None => None }); area_handle.set(match (*unit_opt).clone() { Some(unit) => unit.area, @@ -132,8 +138,8 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { let price_usd = price_usd.clone(); let unit_type_handle: UseStateHandle> = unit_type_handle.clone(); - let rooms_handle: UseStateHandle = rooms_handle.clone(); - let bathrooms_handle: UseStateHandle = bathrooms_handle.clone(); + let rooms_handle: UseStateHandle> = rooms_handle.clone(); + let bathrooms_handle: UseStateHandle> = bathrooms_handle.clone(); let area_handle: UseStateHandle = area_handle.clone(); let media_handle: UseStateHandle = media_handle.clone(); let unit_admin_tag_handle: UseStateHandle = unit_admin_tag_handle.clone(); @@ -145,8 +151,8 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { let price_usd = price_usd.clone(); let unit_type_handle: UseStateHandle> = unit_type_handle.clone(); - let rooms_handle: UseStateHandle = rooms_handle.clone(); - let bathrooms_handle: UseStateHandle = bathrooms_handle.clone(); + let rooms_handle: UseStateHandle> = rooms_handle.clone(); + let bathrooms_handle: UseStateHandle> = bathrooms_handle.clone(); let area_handle: UseStateHandle = area_handle.clone(); let media_handle: UseStateHandle = media_handle.clone(); let unit_admin_tag_handle: UseStateHandle = unit_admin_tag_handle.clone(); @@ -174,8 +180,8 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { project_id, price_usd, unit_type, - rooms, - bathrooms, + rooms: rooms.unwrap_or(0), + bathrooms: bathrooms.unwrap_or(0.0), area, admin_tag, media, @@ -191,8 +197,8 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { id, price_usd: Some(price_usd), unit_type: Some(unit_type), - rooms: Some(rooms), - bathrooms: Some(bathrooms), + rooms: Some(rooms.unwrap_or(0)), + bathrooms: Some(bathrooms.unwrap_or(0.0)), area: Some(area), admin_tag: Some(admin_tag), media: Some(media), @@ -210,11 +216,71 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { html! { <> label={String::from("Precio en USD")} required={true} value={price_usd.clone()} onchange={onchange_number_cb}/> - label={String::from("Area en m^2")} required={true} value={area_handle.clone()} onchange={onchange_number_cb_2.clone()}/> - label={String::from("Cant. de habitaciones")} required={true} value={rooms_handle.clone()} onchange={onchange_number_cb_3.clone()}/> - label={String::from("Cant. de baños")} required={true} value={bathrooms_handle.clone()} onchange={onchange_number_cb_2}/> + label={String::from("Area en m^2")} required={true} value={area_handle.clone()} onchange={onchange_number_cb_2.clone()}/> + // Rooms handle + {if (*rooms_handle).clone().is_none() { + match props.edittype.clone() { + EditType::New => html! { +
+
{"Cant. de habitaciones"}
+ selected={rooms_handle} options={ (1..10).collect::>() } onchange={onselect_cb_2} /> +
+ }, + EditType::Existing(_) => if *user_typed { + html! { +
+
{"Cant. de habitaciones"}
+ selected={rooms_handle} options={ (1..10).collect::>() } onchange={onselect_cb_2} /> +
+ } + } else { + html! {} + } + } + } else { + html! { +
+
{"Cant. de habitaciones"}
+ selected={rooms_handle} options={ (1..10).collect::>() } onchange={onselect_cb_2} /> +
+ } + } + } + + + // Bathrooms handle + {if (*bathrooms_handle).clone().is_none() { + match props.edittype.clone() { + EditType::New => html! { +
+
{"Cant. de baños"}
+ selected={bathrooms_handle} options={ Vec::from([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0]) } onchange={onselect_cb_3} /> +
+ }, + EditType::Existing(_) => if *user_typed { + html! { +
+
{"Cant. de baños"}
+ selected={bathrooms_handle} options={ Vec::from([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0]) } onchange={onselect_cb_3} /> +
+ } + } else { + html! {} + } + } + } else { + html! { +
+
{"Cant. de baños"}
+ selected={bathrooms_handle} options={ Vec::from([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0]) } onchange={onselect_cb_3} /> +
+ } + } + } + + // Unit type dropdown {if (*unit_type_handle).clone().is_none() { match props.edittype.clone() { @@ -244,8 +310,9 @@ pub fn unit_fields(props: &UnitFieldsProps) -> Html { } } } + - +
{"Actualizar"}
diff --git a/src/pages/details.rs b/src/pages/details.rs index 6ce68df..4c690c3 100644 --- a/src/pages/details.rs +++ b/src/pages/details.rs @@ -361,7 +361,10 @@ pub fn create_unit_selection_menu( UnitType::ForSale => html! { <> -
{format!("Unidad {}", ALPHABET_LETTERS.chars().nth(index).unwrap_or_else(|| index.to_string().chars().nth(1).unwrap()))}
+
{match unit.admin_tag.clone() { + Some(admin_tag) => admin_tag, + None => {format!("Unidad {}", ALPHABET_LETTERS.chars().nth(index).unwrap_or_else(|| index.to_string().chars().nth(1).unwrap()))} + }}
}, UnitType::NotForSale => html! {