From 838e99fd1577c52121e148efabcd624114a8b9ad Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 11 Jun 2025 02:54:27 +0100 Subject: fmt: everything --- src/views/macaw/settings.rs | 207 +++++++++++++++++++++++++++++++------------- 1 file changed, 146 insertions(+), 61 deletions(-) (limited to 'src/views/macaw/settings.rs') diff --git a/src/views/macaw/settings.rs b/src/views/macaw/settings.rs index c4cc99b..3e87e3e 100644 --- a/src/views/macaw/settings.rs +++ b/src/views/macaw/settings.rs @@ -1,15 +1,29 @@ use leptos::prelude::*; use profile_settings::ProfileSettings; -use crate::{components::{icon::IconComponent, modal::Modal}, icon::Icon}; +use crate::{ + components::{icon::IconComponent, modal::Modal}, + icon::Icon, +}; mod profile_settings { - use filamento::{error::{AvatarPublishError, CommandError, NickError}, user::User}; - use thiserror::Error; + use filamento::{ + error::{AvatarPublishError, CommandError, NickError}, + user::User, + }; use leptos::prelude::*; - use web_sys::{js_sys::Uint8Array, wasm_bindgen::{prelude::Closure, JsCast, UnwrapThrowExt}, Event, FileReader, HtmlInputElement, ProgressEvent, Url}; + use thiserror::Error; + use web_sys::{ + Event, FileReader, HtmlInputElement, ProgressEvent, Url, + js_sys::Uint8Array, + wasm_bindgen::{JsCast, UnwrapThrowExt, prelude::Closure}, + }; - use crate::{client::Client, files::Files, user::{fetch_avatar, NO_AVATAR}}; + use crate::{ + client::Client, + files::Files, + user::{NO_AVATAR, fetch_avatar}, + }; #[derive(Debug, Clone, Error)] pub enum ProfileSaveError { @@ -36,9 +50,7 @@ mod profile_settings { view! { {move || { if let Some(old_profile) = old_profile.get() { - view! { - - }.into_any() + view! { }.into_any() } else { view! {}.into_any() } @@ -48,7 +60,6 @@ mod profile_settings { #[component] pub fn ProfileForm(old_profile: User) -> impl IntoView { - let client: Client = use_context().expect("no client in context"); // TODO: compartmentalise into error component, form component... @@ -75,14 +86,14 @@ mod profile_settings { let (profile_save_pending, set_profile_save_pending) = signal(false); let profile_upload_data = RwSignal::new(None::>); - let new_nick= RwSignal::new(old_profile.nick.clone().unwrap_or_default().to_string()); + let new_nick = RwSignal::new(old_profile.nick.clone().unwrap_or_default().to_string()); let has_avatar = RwSignal::new(old_profile.avatar.is_some()); let new_avatar_preview_url = RwSignal::new(None::); let remove_avatar = RwSignal::new(false); let from_input = move |ev: Event| { let elem = ev.target().unwrap().unchecked_into::(); - + // let UploadSignal(file_signal) = expect_context(); // file_signal.update(Vec::clear); // Clear list from previous change let files = elem.files().unwrap_throw(); @@ -104,7 +115,7 @@ mod profile_settings { // `.result` valid after the `read_*` completes on FileReader // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/result let result = reader.result().unwrap_throw(); - let data= Uint8Array::new(&result).to_vec(); + let data = Uint8Array::new(&result).to_vec(); // Do whatever you want with the Vec profile_upload_data.set(Some(data)); }) @@ -152,32 +163,32 @@ mod profile_settings { }; if new_nick != old_nick { match client.change_nick(new_nick).await { - Ok(_) => {}, + Ok(_) => {} Err(e) => { set_error.set(Some(ProfileSaveError::Nick(e))); set_profile_save_pending.set(false); return; - }, + } } } if let Some(profile_data) = profile_upload_data.get() { match client.change_avatar(Some(profile_data)).await { - Ok(_) => {}, + Ok(_) => {} Err(e) => { set_error.set(Some(ProfileSaveError::Avatar(e))); set_profile_save_pending.set(false); return; - }, + } } } else if remove_avatar.get() { match client.change_avatar(None).await { - Ok(_) => {}, + Ok(_) => {} Err(e) => { set_error.set(Some(ProfileSaveError::Avatar(e))); set_profile_save_pending.set(false); return; - }, + } } } @@ -200,45 +211,65 @@ mod profile_settings {

Profile Preview

-
{move || { - let nick = new_nick.get(); - if nick.is_empty() { - old_profile.jid.to_string() - } else { - nick - } - }}
+
+ {move || { + let nick = new_nick.get(); + if nick.is_empty() { old_profile.jid.to_string() } else { nick } + }} +
-
+ {success_message} {error_message}
-

Nick

- +

Nick

+

Avatar

- - + + {move || { if has_avatar.get() { view! { - Remove Avatar - }.into_any() + + Remove Avatar + + } + .into_any() } else { view! {}.into_any() } @@ -246,7 +277,12 @@ mod profile_settings {

- +
} @@ -266,31 +302,81 @@ pub fn Settings() -> impl IntoView { let show_settings: RwSignal> = use_context().unwrap(); view! { - +

Settings

- +
-
Account
-
Chat
-
Privacy
-
Profile
+
+ Account +
+
+ Chat +
+
+ Privacy +
+
+ Profile +
- {move || if let Some(page) = show_settings.get() { - match page { - SettingsPage::Account => view! {
"Account settings coming soon!"
}.into_any(), - SettingsPage::Chat => view! {
"Chat settings coming soon!"
}.into_any(), - SettingsPage::Profile => view! { }.into_any(), - SettingsPage::Privacy => view! {
"Privacy settings coming soon!"
}.into_any(), + {move || { + if let Some(page) = show_settings.get() { + match page { + SettingsPage::Account => { + view! { +
+ "Account settings coming soon!" +
+ } + .into_any() + } + SettingsPage::Chat => { + view! { +
+ "Chat settings coming soon!" +
+ } + .into_any() + } + SettingsPage::Profile => { + view! { }.into_any() + } + SettingsPage::Privacy => { + view! { +
+ "Privacy settings coming soon!" +
+ } + .into_any() + } + } + } else { + view! {}.into_any() } - } else { - view! {}.into_any() }}
@@ -298,4 +384,3 @@ pub fn Settings() -> impl IntoView { } } - -- cgit