diff --git a/Cargo.toml b/Cargo.toml index f11de23..68f7b5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ leptos_axum = { version = "0.7.0", optional = true } leptos_meta = { version = "0.7.0" } tokio = { version = "1", features = ["rt-multi-thread"], optional = true } wasm-bindgen = { version = "=0.2.100", optional = true } -aws-sdk-dynamodb = "1.74.0" -aws-config = "1.6.2" +aws-sdk-dynamodb = { version = "1.74.0", optional = true } +aws-config = { version = "1.6.2", optional = true } serde = "1.0.219" [features] @@ -29,6 +29,8 @@ ssr = [ "dep:axum", "dep:tokio", "dep:leptos_axum", + "dep:aws-sdk-dynamodb", + "dep:aws-config", "leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", diff --git a/src/pages/home_page.rs b/src/pages/home_page.rs index 8162c7e..be73265 100644 --- a/src/pages/home_page.rs +++ b/src/pages/home_page.rs @@ -1,21 +1,23 @@ use crate::components::{ActionButton, OutlinedTextField}; use leptos::prelude::*; use leptos::leptos_dom::logging::console_log; -use leptos::task::spawn_local; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct StudentSubmission { - testing_value: Option, + first_name: String, + last_name: String } -#[server] +#[server(CreateSampleSubmission)] pub async fn create_sample_submission() -> Result { 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("Getting values from API"); + match dbclient .get_item() .table_name("student-applications") @@ -25,12 +27,12 @@ pub async fn create_sample_submission() -> Result { println!("Found submission with passed key."); - let value = output.item - .unwrap() - .get("studentFirstName").unwrap() - .as_s().unwrap().clone(); + let item = output.item.unwrap(); + let first_name = item.get("studentFirstName").unwrap().as_s().unwrap().clone(); + let last_name = item.get("studentLastName").unwrap().as_s().unwrap().clone(); Ok(StudentSubmission { - testing_value: Some(value), + first_name: first_name, + last_name: last_name }) } Err(e) => Err(ServerFnError::new("Couldn't find a submission with that ID.")) @@ -42,20 +44,26 @@ pub fn HomePage() -> impl IntoView { // Creates a reactive value to update the button let count = RwSignal::new(0); let elements_disabled = RwSignal::new(false); + let server_resource = Resource::new(|| {}, |_| async { + create_sample_submission().await.unwrap() + }); let on_click = move |_| { *count.write() += 1; *elements_disabled.write() = count.get() == 10; - spawn_local(async { - let response = create_sample_submission().await; - match response { - Ok(submission) => console_log(submission.testing_value.unwrap_or("Default value.".to_string()).as_str()), - Err(_) => console_log("Failed to get correct information.") - }; - }); }; view! {

"Welcome to Leptos!"

+

+ "Lillian's reported full name from the API: " + "Loading..." }> + {move || { + server_resource.get().map(|submission| { + view! { {submission.first_name}" "{submission.last_name} } + }) + }} + +