From 523cb8b90f3d3b2229759522f57bf0c3f1919426 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 23 Jun 2024 17:12:52 +0200 Subject: [PATCH] fix(web): registration page should work now --- web/src/components/post.rs | 2 +- web/src/page/register.rs | 47 ++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/web/src/components/post.rs b/web/src/components/post.rs index 6008632..f4b071e 100644 --- a/web/src/components/post.rs +++ b/web/src/components/post.rs @@ -131,7 +131,7 @@ pub fn PostBox(advanced: WriteSignal) -> impl IntoView { for mention in mentions.get().as_deref().unwrap_or(&[]) { to_vec.push(mention.to_string()); } - let payload = serde_json::Value::Object(serde_json::Map::default()) + let payload = apb::new() .set_object_type(Some(apb::ObjectType::Note)) .set_summary(summary.as_deref()) .set_content(Some(&content)) diff --git a/web/src/page/register.rs b/web/src/page/register.rs index 076b2e3..fc9a2c3 100644 --- a/web/src/page/register.rs +++ b/web/src/page/register.rs @@ -2,6 +2,23 @@ use leptos::*; use reqwest::Method; use crate::prelude::*; +macro_rules! get_ref { + ($r:ident) => { + $r.get().map(|x| x.value()).filter(|x| !x.is_empty()) + } +} + +// TODO this should get moved in a common crate so its not duplicated across FE/BE +#[derive(Debug, Clone, serde::Serialize)] +pub struct RegisterForm { + username: String, + password: String, + display_name: Option, + summary: Option, + avatar_url: Option, + banner_url: Option, +} + #[component] pub fn RegisterPage() -> impl IntoView { let auth = use_context::().expect("missing auth context"); @@ -17,17 +34,29 @@ pub fn RegisterPage() -> impl IntoView {
no credentials provided } + )); + } + spawn_local(async move { - match Http::request::<()>( - Method::PUT, &format!("{URL_BASE}/auth"), None, auth - ).await { - Ok(_x) => {}, - Err(e) => set_error.set(Some( + let payload = RegisterForm { + username: email.unwrap_or_default(), + password: password.unwrap_or_default(), + display_name, summary, avatar_url, banner_url + }; + if let Err(e) = Http::request(Method::PUT, &format!("{URL_BASE}/auth"), Some(&payload), auth).await { + set_error.set(Some( view! {
{e.to_string()}
} - )), + )); } }); } >