diff --git a/src/backend/api/mod.rs b/src/backend/api/mod.rs index 552fba1..3796db3 100644 --- a/src/backend/api/mod.rs +++ b/src/backend/api/mod.rs @@ -126,3 +126,8 @@ pub async fn edit_list( }; Ok(Json(DbEdit::view(params, &data)?)) } + +/// Trims the string param, and converts to None if it is empty +fn empty_to_none(val: &mut Option) { + (*val) = val.as_ref().map(|s| s.trim().to_owned()); +} diff --git a/src/backend/api/user.rs b/src/backend/api/user.rs index 838f2da..0061ce9 100644 --- a/src/backend/api/user.rs +++ b/src/backend/api/user.rs @@ -1,4 +1,4 @@ -use super::check_is_admin; +use super::{check_is_admin, empty_to_none}; use crate::{ backend::{ database::{conflict::DbConflict, read_jwt_secret, IbisData}, @@ -147,8 +147,10 @@ pub(in crate::backend::api) async fn get_user( #[debug_handler] pub(in crate::backend::api) async fn update_user_profile( data: Data, - Form(params): Form, + Form(mut params): Form, ) -> MyResult> { + empty_to_none(&mut params.display_name); + empty_to_none(&mut params.bio); DbPerson::update_profile(¶ms, &data)?; Ok(Json(SuccessResponse::default())) } diff --git a/src/frontend/api.rs b/src/frontend/api.rs index b6f3e6b..1d647e2 100644 --- a/src/frontend/api.rs +++ b/src/frontend/api.rs @@ -222,7 +222,6 @@ impl ApiClient { &self, data: UpdateUserForm, ) -> Result { - log::info!("{:?}", &data); self.post("/api/v1/account/update", Some(data)).await } diff --git a/src/frontend/pages/login.rs b/src/frontend/pages/login.rs index ea6e4b4..f251b49 100644 --- a/src/frontend/pages/login.rs +++ b/src/frontend/pages/login.rs @@ -7,7 +7,7 @@ use leptos_router::components::Redirect; #[component] pub fn Login() -> impl IntoView { - let (login_response, set_login_response) = signal(None::<()>); + let (login_response, set_login_response) = signal(false); let (login_error, set_login_error) = signal(None::); let (wait_for_response, set_wait_for_response) = signal(false); @@ -22,7 +22,7 @@ pub fn Login() -> impl IntoView { match result { Ok(_res) => { site().refetch(); - set_login_response.update(|v| *v = Some(())); + set_login_response.set(true); set_login_error.update(|e| *e = None); } Err(err) => { @@ -38,7 +38,7 @@ pub fn Login() -> impl IntoView { view! { impl IntoView { - let (register_response, set_register_response) = signal(None::<()>); + let (register_response, set_register_response) = signal(false); let (register_error, set_register_error) = signal(None::); let (wait_for_response, set_wait_for_response) = signal(false); @@ -17,19 +17,19 @@ pub fn Register() -> impl IntoView { let credentials = RegisterUserForm { username, password }; info!("Try to register new account for {}", credentials.username); async move { - set_wait_for_response.update(|w| *w = true); + set_wait_for_response.set(true); let result = CLIENT.register(credentials).await; - set_wait_for_response.update(|w| *w = false); + set_wait_for_response.set(false); match result { Ok(_res) => { site().refetch(); - set_register_response.update(|v| *v = Some(())); - set_register_error.update(|e| *e = None); + set_register_response.set(true); + set_register_error.set(None); } Err(err) => { let msg = err.to_string(); log::warn!("Unable to register new account: {msg}"); - set_register_error.update(|e| *e = Some(msg)); + set_register_error.set(Some(msg)); } } } @@ -39,7 +39,7 @@ pub fn Register() -> impl IntoView { view! { impl IntoView { + let (saved, set_saved) = signal(false); let (submit_error, set_submit_error) = signal(None::); let submit_action = Action::new(move |form: &UpdateUserForm| { @@ -17,12 +18,14 @@ pub fn UserEditProfile() -> impl IntoView { let result = CLIENT.update_user_profile(form).await; match result { Ok(_res) => { - set_submit_error.update(|e| *e = None); + site().refetch(); + set_saved.set(true); + set_submit_error.set(None); } Err(err) => { let msg = err.to_string(); log::warn!("Unable to update profile: {msg}"); - set_submit_error.update(|e| *e = Some(msg)); + set_submit_error.set(Some(msg)); } } } @@ -56,6 +59,7 @@ pub fn UserEditProfile() -> impl IntoView { id="displayname" class="w-80 input input-secondary input-bordered" prop:value=display_name + value=display_name on:change=move |ev| { let val = event_target_value(&ev); set_display_name.set(val); @@ -74,7 +78,9 @@ pub fn UserEditProfile() -> impl IntoView { let val = evt.target().value(); set_bio.set(val); } - > + > + bio.get() + + + +
+
+ Saved! +
+
+
} }