diff --git a/src/components/text_field.rs b/src/components/text_field.rs index 173ee5a..5e831c1 100644 --- a/src/components/text_field.rs +++ b/src/components/text_field.rs @@ -57,8 +57,8 @@ pub fn OutlinedTextField( #[prop(optional, into)] placeholder: String, #[prop(into)] data_member: String, // should this be an RwSignal?? #[prop()] data_map: RwSignal>, - #[prop(optional)] input_type: TextFieldType, - #[prop(into, optional)] disabled: Signal, + #[prop(optional, into)] input_type: Signal, + #[prop(optional, into)] disabled: Signal, #[prop(optional, into)] name: String, #[prop(optional, into)] label: String, #[prop(optional, into)] required: Signal @@ -69,13 +69,20 @@ pub fn OutlinedTextField( let validator_context = use_validation_context() .expect("FormValidSignal was not found"); - let raw_value = RwSignal::new(data_map.get_untracked() - .get(&data_member) - .unwrap_or(&ValueType::String(None)) - .to_string()); + let raw_value = Signal::derive({ + let data_member = data_member.clone(); + move || + data_map + .get() + .get(&data_member) + .unwrap_or(&ValueType::String(None)) + .to_string() + }); let dirty = RwSignal::new(false); - let error = RwSignal::new(validate(required.get_untracked(), &raw_value.get_untracked(), &input_type)); + let error = Signal::derive(move || + validate(required.get(), &raw_value.get(), &input_type.get()) + ); let show_errors = Signal::derive(move || { dirty.get() && matches!(error.get(), ValidationState::Invalid(_)) }); @@ -90,10 +97,10 @@ pub fn OutlinedTextField( }); }); - let str_type = match input_type { + let str_type = Signal::derive(move || match input_type.get_untracked() { TextFieldType::Number => "number", _ => "text" // This is fine even for emails, as we're doing our own validation. - }; + }); let on_blur = move |_| { // Check validity of input's current value. The value will be updated by on_input, @@ -107,9 +114,7 @@ pub fn OutlinedTextField( let data_member = data_member.clone(); move |e| { let to_parse = event_target_value(&e); - raw_value.set(to_parse.clone()); - error.set(validate(required.get(), &to_parse, &input_type)); - let into_map = match input_type { + let into_map = match input_type.get() { TextFieldType::Number => ValueType::Number(Some(to_parse)), _ => ValueType::String(Some(to_parse)) }; @@ -137,11 +142,7 @@ pub fn OutlinedTextField( disabled={disabled} placeholder={placeholder} prop:name=name - prop:value=move || data_map - .get() // HashMap - .get(&data_member) // Option - .unwrap_or(&ValueType::String(None)) // ValueType - .to_string() + prop:value=raw_value on:input=on_input on:blur=on_blur /> diff --git a/src/components/toasts/toast.rs b/src/components/toasts/toast.rs index ab58894..7cfeee9 100644 --- a/src/components/toasts/toast.rs +++ b/src/components/toasts/toast.rs @@ -1,7 +1,7 @@ use std::time::Duration; use leptos::prelude::*; use leptos_animate::animate; -use leptos_animate::animations::classes::In; +use leptos_animate::animations::classes::{In, Out}; #[component] pub fn Toast( @@ -17,11 +17,19 @@ pub fn Toast( ); view! { -
+

{title}

{message}

diff --git a/src/components/toasts/toast_list.rs b/src/components/toasts/toast_list.rs index ef3a028..c7f4639 100644 --- a/src/components/toasts/toast_list.rs +++ b/src/components/toasts/toast_list.rs @@ -57,7 +57,7 @@ pub fn ToastList( view! { {children()} -
+
impl IntoView { logo="/PHS_Stacked_Acronym.png" path="/" /> - - -
-
- - - + + +
+
+ - -
-
- - + + + +
+
+ + + } } @@ -349,15 +351,6 @@ fn ScholarshipForm( /// submission fails, this function is not run. #[prop(into)] on_submit: Callback<()> ) -> impl IntoView { - // let result_msg = Signal::derive(move || { - // match submit_status.get() { - // SubmitStatus::Idle => "".into(), - // SubmitStatus::Sending => "Sending submission...".into(), - // SubmitStatus::Success => "Success".into(), - // SubmitStatus::Error(msg) => format!("Error: {}", msg), - // } - // }); - let submit_action = ServerAction::::new(); let submit_status = RwSignal::new(SubmitStatus::Idle); @@ -381,17 +374,6 @@ fn ScholarshipForm( } } }); - - let comparison_list = Resource::new( - move || scholarship_id.get(), // There's no input to this function. - async move |_| { - get_comparison_info().await - .unwrap_or_else(|e| { - log!("Failed to get comparison info: {:?}", e); - Vec::new() - }) - } - ); let comparison_lists = Resource::new( move || scholarship_id.get().is_some(), @@ -476,6 +458,8 @@ fn ScholarshipForm( // fafsa_required, award_to, transcript_required, recipient_selection, essay_requirement (and prompt) // award_night_remarks + let mut toasts = expect_context::(); + let on_submit = move |_| { let mut info = ExpandableInfo::new(scholarship_id.get().unwrap_or_default()); info.data = form_data.get(); @@ -485,6 +469,20 @@ fn ScholarshipForm( info }); }; + + Effect::new(move || { + submit_action.value().get().is_some() + .then(|| { + log!("Displaying toasts!"); + toasts.toast( + Toast::new() + .id(uuid::Uuid::new_v4()) + .msg("Succesfully submitted.") + ); + + submit_action.clear(); + }); + }); let create_comps = ServerAction::::new();