From 9402c82a30412b95da62f9f0a9cebceb90b5ca4b Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Sun, 25 May 2025 20:23:18 -0400 Subject: [PATCH] style: run cargo fmt command --- Cargo.toml | 2 +- src/app.rs | 2 +- src/components/text_field.rs | 4 +-- src/pages/home_page.rs | 60 +++++++++++++++++++++--------------- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68f7b5b..f9bd0bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ panic = "abort" [package.metadata.leptos] # The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name -output-name = "scholarships-rs" +output-name = "scholarships-rs-wasm" # The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup. site-root = "target/site" diff --git a/src/app.rs b/src/app.rs index 5fd2cbe..f6eb0c2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -33,7 +33,7 @@ pub fn App() -> impl IntoView { view! { // injects a stylesheet into the document // id=leptos means cargo-leptos will hot-reload this stylesheet - + // sets the document title diff --git a/src/components/text_field.rs b/src/components/text_field.rs index 3167905..a0caf3b 100644 --- a/src/components/text_field.rs +++ b/src/components/text_field.rs @@ -6,7 +6,7 @@ pub fn OutlinedTextField( #[prop(default = RwSignal::new("".to_string()))] value: RwSignal<String>, #[prop(default = RwSignal::new(false))] disabled: RwSignal<bool>, #[prop(default = String::from(""))] name: String, - #[prop(default = String::from(""))] label: String + #[prop(default = String::from(""))] label: String, ) -> impl IntoView { view! ( <label> @@ -16,7 +16,7 @@ pub fn OutlinedTextField( class=(["border-red-700"], move || !disabled.get()) class=(["border-gray-600", "pointer-events-none"], move || disabled.get()) r#type="text" - disabled={disabled.get()} + disabled={move || disabled.get()} placeholder={placeholder} prop:name=name bind:value=value // This is a two-way binding - it is allowed to read *and* write. diff --git a/src/pages/home_page.rs b/src/pages/home_page.rs index 7eae894..fbfdbcd 100644 --- a/src/pages/home_page.rs +++ b/src/pages/home_page.rs @@ -1,25 +1,19 @@ use crate::components::{ActionButton, OutlinedTextField}; -use leptos::prelude::*; use leptos::leptos_dom::logging::console_log; +use leptos::prelude::*; use serde::{Deserialize, Serialize}; #[cfg(feature = "ssr")] -use aws_sdk_dynamodb::{ - Client, - types::AttributeValue, - error::ProvideErrorMetadata -}; +use aws_sdk_dynamodb::{error::ProvideErrorMetadata, types::AttributeValue, Client}; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct StudentInfo { first_name: String, - last_name: String + last_name: String, } -#[server(GetSubmission)] -pub async fn get_submission(id: String) - -> Result<StudentInfo, ServerFnError> { - +#[server(GetSubmission, endpoint = "/get-submission")] +pub async fn get_submission(id: String) -> Result<StudentInfo, ServerFnError> { let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await; let dbclient = Client::new(&config); @@ -35,29 +29,40 @@ pub async fn get_submission(id: String) Ok(output) => { console_log("Found submission with passed key."); let item = output.item.unwrap(); - let first_name = item.get("studentFirstName").unwrap().as_s().unwrap().clone(); + let first_name = item + .get("studentFirstName") + .unwrap() + .as_s() + .unwrap() + .clone(); let last_name = item.get("studentLastName").unwrap().as_s().unwrap().clone(); Ok(StudentInfo { first_name, - last_name + last_name, }) } Err(err) => { let msg = err.message().unwrap_or("Unknown error"); - console_log(format!("Exception while getting submission information: {}", msg).as_str()); + // console_log(format!("Exception while getting submission information: {}", msg).as_str()); Err(ServerFnError::new(msg)) } } } -#[server(CreateSampleSubmission)] +#[server(CreateSampleSubmission, endpoint = "/create-sample-submission")] pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), ServerFnError> { use aws_sdk_dynamodb::{types::AttributeValue, Client}; let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await; let dbclient = Client::new(&config); - console_log(format!("Creating sample submission with name {} {}", student_info.first_name, student_info.last_name).as_str()); + console_log( + format!( + "Creating sample submission with name {} {}", + student_info.first_name, student_info.last_name + ) + .as_str(), + ); let submission_id = String::from("testing_student"); @@ -65,16 +70,24 @@ pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), S .update_item() .table_name("student-applications") .key("Email", AttributeValue::S(submission_id)) - .expression_attribute_values(":studentFirstName", AttributeValue::S(student_info.first_name)) - .expression_attribute_values(":studentLastName", AttributeValue::S(student_info.last_name)) + .expression_attribute_values( + ":studentFirstName", + AttributeValue::S(student_info.first_name), + ) + .expression_attribute_values( + ":studentLastName", + AttributeValue::S(student_info.last_name), + ) .expression_attribute_names("#studentFirstName", "studentFirstName") .expression_attribute_names("#studentLastName", "studentLastName") - .update_expression("SET #studentFirstName = :studentFirstName, #studentLastName = :studentLastName") + .update_expression( + "SET #studentFirstName = :studentFirstName, #studentLastName = :studentLastName", + ) .send() .await { Ok(_) => Ok(()), - Err(err) => Err(ServerFnError::new(err.into_service_error().to_string())) + Err(err) => Err(ServerFnError::new(err.into_service_error().to_string())), } } @@ -86,16 +99,16 @@ pub fn HomePage() -> impl IntoView { let elements_disabled = RwSignal::new(false); let server_resource = Resource::new( - move || { sample_id.get() }, + move || sample_id.get(), async |id| { get_submission(id).await.unwrap_or_else(|e| { console_log(e.to_string().as_str()); StudentInfo { first_name: String::from("Error"), - last_name: String::from("") + last_name: String::from(""), } }) - } + }, ); let on_click = move |_| { *count.write() += 1; @@ -103,7 +116,6 @@ pub fn HomePage() -> impl IntoView { }; let submit_action = ServerAction::<CreateSampleSubmission>::new(); - view! { <h1>"Welcome to Leptos!"</h1> <p>