chore: pc change

This commit is contained in:
alphafetus committed 2025-08-26 09:57:58 -04:00
1 parent 21ba5e45ff
commit f7ca1ecbc5
27 files changed
+926 -262

No files matched your search

+125 -68
View File
@@ -1,38 +1,54 @@
use crate::components::{ActionButton, OutlinedTextField};
use crate::common::StudentInfo;
use leptos::leptos_dom::logging::console_log;
use leptos::prelude::*;
use std::collections::HashMap;
#[cfg(feature = "ssr")]
use aws_sdk_dynamodb::{error::ProvideErrorMetadata, types::AttributeValue, Client};
use crate::app::Unauthenticated;
use crate::common::{StudentInfo, StudentInfoReactive, UserClaims};
use crate::components::{ActionButton, Loading, OutlinedTextField, Select};
use leptos::leptos_dom::logging::console_log;
use leptos::prelude::*;
use leptos_oidc::{Algorithm, AuthLoaded, AuthSignal, Authenticated};
#[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);
console_log(format!("Getting values from API using key {}", id).as_str());
console_log(format!("Getting values from API using username {}", id).as_str());
match dbclient
.get_item()
.table_name("student-applications")
.key("Email", AttributeValue::S(id))
.key("Email", AttributeValue::S(id.clone()))
.send()
.await
{
Ok(output) => {
console_log("Found submission with passed key.");
let item = output.item.unwrap();
let first_name = item
let first_name: String = item
.get("studentFirstName")
.unwrap()
.as_s()
.unwrap()
.clone();
let last_name = item.get("studentLastName").unwrap().as_s().unwrap().clone();
.and_then(|attr| attr.as_s().ok())
.map(|s| s.to_owned())
.unwrap_or_default();
let last_name: String = item
.get("studentLastName")
.and_then(|attr| attr.as_s().ok())
.map(|s| s.to_owned())
.unwrap_or_default();
let math_sat_score = item
.get("mathSAT")
.and_then(|attr| attr.as_n().ok())
.map(|n| n.parse::<i32>().unwrap_or(0))
.unwrap_or_default();
console_log(format!("Got values from API: {} {}", first_name, last_name).as_str());
Ok(StudentInfo {
first_name,
last_name,
math_sat_score,
})
}
Err(err) => {
@@ -43,7 +59,10 @@ pub async fn get_submission(id: String) -> Result<StudentInfo, ServerFnError> {
}
#[server(CreateSampleSubmission, endpoint = "/create-sample-submission")]
pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), ServerFnError> {
pub async fn create_sample_submission(
student_info: StudentInfo,
subject: String,
) -> Result<(), ServerFnError> {
use aws_sdk_dynamodb::{types::AttributeValue, Client};
let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
@@ -51,18 +70,16 @@ pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), S
console_log(
format!(
"Creating sample submission with name {} {}",
student_info.first_name, student_info.last_name
"Creating sample submission with name {} {}, math score {}, and subject {}",
student_info.first_name, student_info.last_name, student_info.math_sat_score, subject
)
.as_str(),
);
let submission_id = String::from("testing_student");
match dbclient
.update_item()
.table_name("student-applications")
.key("Email", AttributeValue::S(submission_id))
.key("Email", AttributeValue::S(subject))
.expression_attribute_values(
":studentFirstName",
AttributeValue::S(student_info.first_name),
@@ -71,10 +88,17 @@ pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), S
":studentLastName",
AttributeValue::S(student_info.last_name),
)
.expression_attribute_values(
":mathScoreSAT",
AttributeValue::N(student_info.math_sat_score.to_string()),
)
.expression_attribute_names("#studentFirstName", "studentFirstName")
.expression_attribute_names("#studentLastName", "studentLastName")
.expression_attribute_names("#mathScoreSAT", "mathScoreSAT")
.update_expression(
"SET #studentFirstName = :studentFirstName, #studentLastName = :studentLastName",
concat!("SET #studentFirstName = :studentFirstName, ",
"#studentLastName = :studentLastName, ",
"#mathScoreSAT = :mathScoreSAT"),
)
.send()
.await
@@ -86,65 +110,98 @@ pub async fn create_sample_submission(student_info: StudentInfo) -> Result<(), S
#[component]
pub fn HomePage() -> impl IntoView {
let sample_id = RwSignal::new("google_113247439743075864879".to_string());
// Creates a reactive value to update the button
let count = RwSignal::new(0);
let elements_disabled = RwSignal::new(false);
let auth = use_context::<AuthSignal>().expect("Couldn't find user information.");
let user_claims = Signal::derive(move || {
auth.with(|auth| {
auth.authenticated().and_then(|data| {
data.decoded_access_token::<UserClaims>(Algorithm::RS256, &["account"])
})
})
});
// Note that the value passed in MUST be equatable.
// We get/unwrap the value repeatedly until we get a simple string value, then clone it so that
// we don't lose access to it in the future, should we need it again.
let server_resource = Resource::new(
move || sample_id.get(),
async |id| {
get_submission(id).await.unwrap_or_else(|e| {
move || user_claims.get().map(|claim| claim.claims.subject.clone()),
async |opt_username| match opt_username {
Some(username) => get_submission(username).await.unwrap_or_else(|e| {
console_log(e.to_string().as_str());
StudentInfo {
first_name: String::from("Error"),
last_name: String::from(""),
math_sat_score: 0,
}
})
}),
None => StudentInfo {
first_name: String::new(),
last_name: String::new(),
math_sat_score: 0,
},
},
);
let on_click = move |_| {
*count.write() += 1;
*elements_disabled.write() = count.get() == 10;
};
let submit_action = ServerAction::<CreateSampleSubmission>::new();
view! {
<h1>"Welcome to Leptos!"</h1>
<p>
"Lillian's reported full name from the API: "
<Suspense fallback=move || view! { <span>"Loading..."</span> }>
{move || {
server_resource.get().map(|submission| {
view! { <span>{submission.first_name}" "{submission.last_name}</span> }
})
}}
</Suspense>
</p>
<ActionForm action=submit_action>
<div>
<OutlinedTextField
label="First Name".into()
placeholder="John".into()
disabled={elements_disabled}
name="student_info[first_name]".into() />
</div>
<div>
<OutlinedTextField
label="Last Name".into()
placeholder="Smith".into()
disabled={elements_disabled}
name="student_info[last_name]".into() />
</div>
<div>
<ActionButton
on:click=on_click
disabled={elements_disabled}
button_type="submit".into()
>
"Submit"
</ActionButton>
</div>
</ActionForm>
<AuthLoaded fallback=Loading>
<Authenticated unauthenticated=Unauthenticated>
// Replace this fallback with a real loading screen.
<Suspense fallback=Loading>
{move || {
server_resource.get().map(|submission: StudentInfo| {
let reactive_info = StudentInfoReactive::new(submission);
let select_value = RwSignal::new(String::from("Math"));
view! {
<p>
"Current user's reported full name from the API: "
{reactive_info.first_name}" "{reactive_info.last_name}
</p>
<form>
<div>
<OutlinedTextField
label="First Name".into()
placeholder="John".into()
value=reactive_info.first_name />
</div>
<div>
<OutlinedTextField
label="Last Name".into()
placeholder="Smith".into()
value=reactive_info.last_name />
</div>
<div>
<OutlinedTextField
label="Testing".into()
placeholder="Test".into()
value=reactive_info.math_sat_score />
</div>
<Select
value_list = vec!["Math".into(), "English".into(), "Science".into()]
value = select_value
/>
<div>
<ActionButton
on:click=move |_| {
submit_action.dispatch(CreateSampleSubmission {
student_info: reactive_info.capture(),
subject: user_claims.get().unwrap().claims.subject.clone()
});
}
>
"Submit"
</ActionButton>
</div>
</form>
}
})
}}
</Suspense>
</Authenticated>
</AuthLoaded>
}
}
+5 -8
View File
@@ -1,23 +1,20 @@
//! This defines the base component of the Chromebook loaner kiosk application.
//! This defines the base component of the Chromebook loaner kiosk application.
//! There are going to be 3 definitive screens that the users are able to see and use:
//! - The username entry screen: users will enter their name and email.
//! - The action selection screen: users will be given a choice regarding their loaner status.
//! - The completion screen: users will be given a success message should their information save.
//! Refer to each component's file for more information about how they work.
use leptos::prelude::*;
use super::{action_selection::ActionSelection, user_entry::UserEntry};
use crate::common::LoanerUser;
use super::{
user_entry::UserEntry,
action_selection::ActionSelection
};
use leptos::prelude::*;
/// Used to keep track of the currently displayed controls.
#[derive(Clone, Copy, PartialEq)]
pub enum LoanerKioskState {
UserEntry,
ActionSelection,
Complete
Complete,
}
/// The base Chromebook loaner kiosk component.
@@ -27,7 +24,7 @@ pub enum LoanerKioskState {
pub fn LoanerKiosk() -> impl IntoView {
let current_state = RwSignal::new(LoanerKioskState::UserEntry);
let user = RwSignal::new(LoanerUser::new());
view! {
<div class="flex w-screen h-screen justify-center items-center">
<UserEntry
+2 -3
View File
@@ -1,4 +1,3 @@
mod loaner_kiosk;
mod user_entry;
mod action_selection;
mod loaner_kiosk;
mod user_entry;
+12 -6
View File
@@ -1,4 +1,4 @@
//! Contains the user entry component.
//! Contains the user entry component.
//! It would be preferred if the user was restricted to a real user account. This is the URL:
//! https://admin.googleapis.com/admin/directory/v1/users?domain=region15.org&projection=BASIC&query=isArchived=false%20isAdmin=false
//! Once they select this, they can then check in/out the loaners under their account.
@@ -6,10 +6,10 @@
//! a service account. That's going to be a pain to set up.
//! For example's sake here, we're just going to take a first name, last name, and email address.
use leptos::leptos_dom::logging::console_log;
use leptos::prelude::*;
use crate::common::LoanerUser;
use crate::components::{ActionButton, OutlinedTextField};
use leptos::leptos_dom::logging::console_log;
use leptos::prelude::*;
/// The user entry component for the loaner kiosk.
///
@@ -20,11 +20,14 @@ use crate::components::{ActionButton, OutlinedTextField};
#[component]
pub fn UserEntry(
/// A callback function used when the control has determined this stage is finished.
#[prop()] mut on_submit: impl FnMut() + 'static,
#[prop()]
mut on_submit: impl FnMut() + 'static,
/// The global user record.
#[prop()] user: RwSignal<LoanerUser>,
#[prop()]
user: RwSignal<LoanerUser>,
/// Whether this control is shown. Required for use with CSS animations.
#[prop()] shown: bool
#[prop()]
shown: bool,
) -> impl IntoView {
let disabled = RwSignal::new(false);
let on_click = move |_| {
@@ -44,16 +47,19 @@ pub fn UserEntry(
label="First Name".into()
placeholder="John".into()
disabled={disabled}
value=RwSignal::new("".to_owned())
/>
<OutlinedTextField
label="Last Name".into()
placeholder="Smith".into()
disabled={disabled}
value=RwSignal::new("".to_owned())
/>
<OutlinedTextField
label="Region 15 Email".into()
placeholder="jsmith@region15.org".into()
disabled={disabled}
value=RwSignal::new("".to_owned())
/>
<ActionButton
on:click=on_click
+1 -1
View File
@@ -1,6 +1,6 @@
mod about_page;
mod home_page;
mod provider_entry;
mod loaner_kiosk;
mod provider_entry;
pub use self::{about_page::*, home_page::*, provider_entry::*};
+38 -19
View File
@@ -1,27 +1,46 @@
use crate::components::{MultiEntry, MultiEntryData, MultiEntryMember, OutlinedTextField};
use crate::app::Unauthenticated;
use crate::common::UserClaims;
use crate::components::{Loading, MultiEntry, MultiEntryData, MultiEntryMember, OutlinedTextField};
use leptos::leptos_dom::logging::console_log;
use leptos::prelude::*;
use leptos_oidc::{Algorithm, AuthLoaded, AuthSignal, Authenticated, LogoutLink};
use serde::{Deserialize, Serialize};
#[component]
pub fn ProviderEntry() -> impl IntoView {
let auth = use_context::<AuthSignal>().expect("Couldn't find auth signal");
let auth_data = auth
.get()
.authenticated()
.and_then(|data| data.decoded_access_token::<UserClaims>(Algorithm::RS256, &["account"]));
let multi_entries: RwSignal<Vec<MultiEntryData>> = RwSignal::new(vec![]);
console_log(format!("User claims: {auth_data:?}").as_str());
view! (
<h1>This is the provider entry page</h1>
<h2>It would usually have a series of questions that we ask the providers</h2>
<div>
<OutlinedTextField
placeholder = "Testing information...".into()
name = "testing_input".into()
label = "This is a testing question.".into()
/>
</div>
<div>
<p>This is an example of the multientry element.</p>
<MultiEntry
entries=multi_entries
name_member=Signal::from(MultiEntryMember::from_str("Entry Name", "name"))
info_member=Signal::from(MultiEntryMember::from_str("Entry Info", "info"))
/>
</div>
<AuthLoaded fallback=Loading>
<Authenticated unauthenticated=Unauthenticated>
<LogoutLink class="text-logout">"Sign out"</LogoutLink>
<h1>This is the provider entry page</h1>
<h2>It would usually have a series of questions that we ask the providers</h2>
<div>
<OutlinedTextField
placeholder = "Testing information...".into()
name = "testing_input".into()
label = "This is a testing question.".into()
value = RwSignal::new("".to_owned())
/>
</div>
<div>
<p>This is an example of the multientry element.</p>
<MultiEntry
entries=multi_entries
name_member=Signal::from(MultiEntryMember::from_str("Entry Name", "name"))
info_member=Signal::from(MultiEntryMember::from_str("Entry Info", "info"))
/>
</div>
</Authenticated>
</AuthLoaded>
)
}