feat: create impromptu demo page
This commit is contained in:
1 parent
8c46ad5dfd
commit
4fc01acd50
14 files changed
+169
-120
No files matched your search
+4
-6
@@ -1,11 +1,9 @@
|
||||
use leptos::prelude::*;
|
||||
use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title};
|
||||
use leptos_oidc::{
|
||||
Auth, AuthParameters, AuthSignal, Challenge, LoginLink,
|
||||
};
|
||||
use leptos_meta::{MetaTags, Stylesheet, Title, provide_meta_context};
|
||||
use leptos_oidc::{Auth, AuthParameters, AuthSignal, Challenge, LoginLink};
|
||||
use leptos_router::{
|
||||
components::{Route, Router, Routes},
|
||||
StaticSegment,
|
||||
components::{Route, Router, Routes},
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
@@ -47,7 +45,7 @@ pub fn App() -> impl IntoView {
|
||||
|
||||
let auth = Auth::signal();
|
||||
provide_context(auth); // allows use of this signal in lower areas of the tree without
|
||||
// explicitly passing it through the html tree
|
||||
// explicitly passing it through the html tree
|
||||
|
||||
let _ = Auth::init(parameters);
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::components::MultiEntryData;
|
||||
use macros::Reactive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::default::Default;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
/// Represents information about a student.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Reactive, Default)]
|
||||
@@ -22,4 +24,22 @@ pub struct StudentInfo {
|
||||
/// The student's desired contact email.
|
||||
#[serde(default)]
|
||||
pub contact_email: String,
|
||||
/// The student's address.
|
||||
#[serde(default)]
|
||||
pub address: String,
|
||||
/// The student's town of residence.
|
||||
#[serde(default)]
|
||||
pub town: String,
|
||||
/// The student's entered phone number.
|
||||
#[serde(default)]
|
||||
pub phone_number: String, // May be stored as a straight number in the future.
|
||||
/// The student's birthdate.
|
||||
#[serde(default)]
|
||||
pub birth_date: DateTime<Utc>,
|
||||
/// The student's gender.
|
||||
#[serde(default)]
|
||||
pub gender: String,
|
||||
/// The student's athletic information.
|
||||
#[serde(default)]
|
||||
pub athletic_info: Vec<MultiEntryData>,
|
||||
}
|
||||
@@ -45,9 +45,11 @@ pub fn CheckboxList(
|
||||
#[prop(default = RwSignal::new(vec![]))] selected: RwSignal<Vec<String>>,
|
||||
#[prop()] items: Vec<String>,
|
||||
#[prop(default = RwSignal::new(false))] disabled: RwSignal<bool>,
|
||||
#[prop(optional, into)] label: String,
|
||||
) -> impl IntoView {
|
||||
view! {
|
||||
<div>
|
||||
<div class="m-1.5 mt-0 mb-0">
|
||||
<span class="font-bold">{label}</span>
|
||||
{items
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
|
||||
@@ -87,14 +87,14 @@ pub fn Entry(
|
||||
#[prop()]
|
||||
info_member: Signal<MultiEntryMember>,
|
||||
) -> impl IntoView {
|
||||
let nameData = entry_data.data.get(&name_member.get().member_name).unwrap();
|
||||
let infoData = entry_data.data.get(&info_member.get().member_name).unwrap();
|
||||
let name_data = entry_data.data.get(&name_member.get().member_name).unwrap();
|
||||
let info_data = entry_data.data.get(&info_member.get().member_name).unwrap();
|
||||
|
||||
view! {
|
||||
// This div MUST have the same spacing CSS as the second-level header div
|
||||
<div class="flex rounded-sm transition-shadow shadow-sm hover:shadow-lg/30 p-3 m-1">
|
||||
<span class="flex-1">{nameData.as_string()}</span>
|
||||
<span class="flex-1">{infoData.as_string()}</span>
|
||||
<span class="flex-1">{name_data.as_string()}</span>
|
||||
<span class="flex-1">{info_data.as_string()}</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use leptos::prelude::*;
|
||||
|
||||
/// A panel for use in visual separation of a group of components. A `Panel` arranges
|
||||
/// a series of elements within a shaded rectangle using the flexbox column layout.
|
||||
///
|
||||
///
|
||||
/// It takes a series of children. Usually these would be in the form of a `Row` element,
|
||||
/// which will arrange its own children in a row within the panel, however it can be any
|
||||
/// HTML element.
|
||||
///
|
||||
///
|
||||
/// Example:
|
||||
/// ```
|
||||
/// view! {
|
||||
@@ -24,14 +24,16 @@ use leptos::prelude::*;
|
||||
/// ```
|
||||
#[component]
|
||||
pub fn Panel(
|
||||
children: Children
|
||||
#[prop(optional, default = false)] hidden: bool,
|
||||
#[prop(optional)] children: Option<Children>
|
||||
) -> impl IntoView {
|
||||
view! {
|
||||
<div
|
||||
class="flex flex-col gap-2 p-2 m-4 flex-1
|
||||
border-1 border-gray-600/10
|
||||
rounded-md shadow-[0_0_6px_rgba(0,0,0,0.50)]">
|
||||
{children()}
|
||||
rounded-md shadow-[0_0_6px_rgba(0,0,0,0.50)]"
|
||||
class=(["hidden"], hidden) >
|
||||
{children.and_then(move |t| {Some(t())})}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,11 @@ pub fn RadioList(
|
||||
#[prop(default = RwSignal::new(String::new()))] selected: RwSignal<String>,
|
||||
#[prop()] items: Vec<String>,
|
||||
#[prop(default = RwSignal::new(false))] disabled: RwSignal<bool>,
|
||||
#[prop(optional, into)] label: String,
|
||||
) -> impl IntoView {
|
||||
view! {
|
||||
<div>
|
||||
<div class="m-1.5 mt-0 mb-0">
|
||||
<span class="font-bold">{label}</span>
|
||||
{items
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use leptos::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn Row(
|
||||
children: Children
|
||||
) -> impl IntoView {
|
||||
pub fn Row(children: Children) -> impl IntoView {
|
||||
view! {
|
||||
<div class="flex flex-row gap-2 flex-1">
|
||||
{children()}
|
||||
|
||||
@@ -8,15 +8,15 @@ use leptos::prelude::*;
|
||||
pub fn Select(
|
||||
#[prop(default = vec!["Test Value".into()])] value_list: Vec<String>,
|
||||
#[prop(default = RwSignal::new("".into()))] value: RwSignal<String>,
|
||||
#[prop(default = RwSignal::new("".into()))] label: RwSignal<String>,
|
||||
#[prop(optional, into)] label: String,
|
||||
#[prop(default = RwSignal::new(false))] disabled: RwSignal<bool>,
|
||||
) -> impl IntoView {
|
||||
view! {
|
||||
<div>
|
||||
<label>
|
||||
{label}
|
||||
<div class="flex flex-1">
|
||||
<label class="flex flex-col flex-1">
|
||||
<span class="ml-1.5 mb-0 font-bold">{label}</span>
|
||||
<select
|
||||
class="relative border-2 m-1.5 p-1.5 rounded-md
|
||||
class="relative flex-1 border-2 m-1.5 mt-0 p-1.5 rounded-md
|
||||
transition-border duration-150
|
||||
border-red-700 bg-transparent
|
||||
disabled:border-gray-600 disabled:pointer-events-none disabled:bg-gray-600/33"
|
||||
|
||||
@@ -1,30 +1,35 @@
|
||||
use std::str::FromStr;
|
||||
use leptos::prelude::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[component]
|
||||
pub fn OutlinedTextField<T>(
|
||||
#[prop(default = T::default(), into)] placeholder: T,
|
||||
#[prop(default = RwSignal::new(T::default()))] value: RwSignal<T>,
|
||||
#[prop(default = RwSignal::new(false))] disabled: RwSignal<bool>,
|
||||
#[prop(default = String::from(""), into)] name: String,
|
||||
#[prop(default = String::from(""), into)] label: String,
|
||||
#[prop(default = String::from(""), into)] input_type: String,
|
||||
#[prop(optional, into)] placeholder: T,
|
||||
#[prop(optional)] value: RwSignal<T>,
|
||||
#[prop(optional)] disabled: RwSignal<bool>,
|
||||
#[prop(optional)] error: RwSignal<bool>,
|
||||
#[prop(optional, into)] name: String,
|
||||
#[prop(optional, into)] label: String,
|
||||
#[prop(optional, into)] input_type: String,
|
||||
) -> impl IntoView
|
||||
where
|
||||
T: Default + 'static + FromStr + ToString + PartialEq + Send + Sync + Clone
|
||||
T: Default + 'static + FromStr + ToString + PartialEq + Send + Sync + Clone,
|
||||
{
|
||||
// Parsing logic for non-string types which happens on each input.
|
||||
let on_input = move |e| {
|
||||
let input_value = event_target_value(&e);
|
||||
let parsed_value = T::from_str(&input_value)
|
||||
.unwrap_or_default();
|
||||
value.set(parsed_value);
|
||||
let can_parse = T::from_str(&input_value);
|
||||
if let Ok(parsed_value) = can_parse {
|
||||
value.set(parsed_value);
|
||||
} else {
|
||||
error.set(true);
|
||||
value.set(T::default());
|
||||
}
|
||||
};
|
||||
|
||||
view! (
|
||||
<div class="flex flex-1">
|
||||
<label class="flex flex-col flex-1">
|
||||
<span class="block ml-1.5 mb-0">{label}</span>
|
||||
<span class="block ml-1.5 mb-0 font-bold">{label}</span>
|
||||
<input
|
||||
class="border-2 m-1.5 p-1.5 mt-0 rounded-md bg-transparent relative flex-1
|
||||
transition-all duration-150
|
||||
@@ -35,7 +40,7 @@ where
|
||||
placeholder={placeholder.to_string()}
|
||||
prop:name=name
|
||||
prop:value={move || value.get().to_string()} // Sets the initial value.
|
||||
on:input=on_input // Sets the value on each input.
|
||||
on:input=on_input
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ async fn main() {
|
||||
use axum::Router;
|
||||
use leptos::logging::log;
|
||||
use leptos::prelude::*;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use leptos_axum::{LeptosRoutes, generate_route_list};
|
||||
use scholarships_rs::app::*;
|
||||
|
||||
let conf = get_configuration(None).unwrap();
|
||||
|
||||
+87
-66
@@ -1,16 +1,13 @@
|
||||
// Server dependencies
|
||||
#[cfg(feature = "ssr")]
|
||||
use aws_sdk_dynamodb::{error::ProvideErrorMetadata, types::AttributeValue, Client};
|
||||
use aws_sdk_dynamodb::{Client, error::ProvideErrorMetadata, types::AttributeValue};
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
use serde_dynamo::{from_item, to_item};
|
||||
|
||||
use crate::app::Unauthenticated;
|
||||
use crate::common::{StudentInfo, UserClaims};
|
||||
use crate::components::{
|
||||
ActionButton, CheckboxList, Loading, OutlinedTextField, Panel, Row, Select,
|
||||
RadioList
|
||||
};
|
||||
use crate::components::{ActionButton, CheckboxList, Loading, MultiEntry, MultiEntryMember, OutlinedTextField, OutlinedTextFieldPropsBuilder_Error_Repeated_field_disabled, Panel, RadioList, Row, Select};
|
||||
use leptos::leptos_dom::logging::console_log;
|
||||
use leptos::prelude::*;
|
||||
use leptos_oidc::{Algorithm, AuthLoaded, AuthSignal, Authenticated};
|
||||
@@ -18,7 +15,6 @@ use traits::{AsReactive, ReactiveCapture};
|
||||
|
||||
#[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);
|
||||
|
||||
@@ -36,11 +32,11 @@ pub async fn get_submission(id: String) -> Result<StudentInfo, ServerFnError> {
|
||||
Ok(output) => {
|
||||
if let Some(item) = output.item {
|
||||
console_log(format!("Found item from API: {item:?}").as_str());
|
||||
Ok(from_item(item).unwrap())
|
||||
Ok(from_item(item)?)
|
||||
} else {
|
||||
console_log("Couldn't find entry, returning default.");
|
||||
let mut info = StudentInfo::default();
|
||||
info.Email = id; // Set the correct subject
|
||||
info.Email = id; // Set the correct subject
|
||||
Ok(info)
|
||||
}
|
||||
}
|
||||
@@ -52,10 +48,7 @@ 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) -> Result<(), ServerFnError> {
|
||||
let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
|
||||
let dbclient = Client::new(&config);
|
||||
|
||||
@@ -68,19 +61,20 @@ pub async fn create_sample_submission(
|
||||
.put_item()
|
||||
.table_name("student-applications")
|
||||
.set_item(Some(item))
|
||||
.send().await
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
// The student's information was successfully created
|
||||
console_log(format!("Set up student information: {:?}", student_info).as_str());
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
// There was an error while creating the student's information
|
||||
let msg = err.message().unwrap_or("An unknown error occurred.");
|
||||
console_log(format!("Error creating sample submission: {}", msg).as_str());
|
||||
Err(ServerFnError::new(msg))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,14 +97,11 @@ pub fn HomePage() -> impl IntoView {
|
||||
let server_resource = Resource::new(
|
||||
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::default()
|
||||
}
|
||||
),
|
||||
None => StudentInfo::default()
|
||||
Some(username) => get_submission(username).await.unwrap_or_else(|e| {
|
||||
console_log(e.to_string().as_str());
|
||||
StudentInfo::default()
|
||||
}),
|
||||
None => StudentInfo::default(),
|
||||
},
|
||||
);
|
||||
let submit_action = ServerAction::<CreateSampleSubmission>::new();
|
||||
@@ -125,28 +116,38 @@ pub fn HomePage() -> impl IntoView {
|
||||
.get()
|
||||
.map(|submission: StudentInfo| {
|
||||
let reactive_info = submission.as_reactive();
|
||||
let select_value = RwSignal::new(String::from("Math"));
|
||||
let chk_select = RwSignal::new(vec!["Testing 2".into()]);
|
||||
let elements_disabled = RwSignal::new(false);
|
||||
let radio_value = RwSignal::new(String::from("Test"));
|
||||
let result_msg = Signal::derive(move || {
|
||||
// Eventually, this function will show and hide a loading symbol
|
||||
// and a success checkmark.
|
||||
if submit_action.pending().get() {
|
||||
elements_disabled.set(true);
|
||||
"Sending request...".to_owned()
|
||||
} else {
|
||||
elements_disabled.set(false);
|
||||
if let Some(result) = submit_action.value().get() {
|
||||
match result {
|
||||
Ok(_) => "Request sent successfully.".to_owned(),
|
||||
Err(e) => format!("Failed to send request: {:?}", e)
|
||||
}
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
view! {
|
||||
<div class="flex flex-row">
|
||||
<Row>
|
||||
<div class="flex flex-col flex-1"/>
|
||||
<Panel>
|
||||
<Row>
|
||||
<p>
|
||||
"Testing paragraph! This panel should be the same size as the other."
|
||||
</p>
|
||||
<h1 class="text-3xl font-bold">
|
||||
"Region 15 Scholarship Application (DEMO)"
|
||||
</h1>
|
||||
</Row>
|
||||
<Row>
|
||||
<p>"Current user's subject ID: "{reactive_info.Email}</p>
|
||||
</Row>
|
||||
</Panel>
|
||||
<Panel>
|
||||
<Row>
|
||||
<p>
|
||||
"Current user's reported full name from the API: "
|
||||
{reactive_info.first_name}" " {reactive_info.last_name}
|
||||
<p class="text-sm">
|
||||
"This is a very simple demonstration of the scholarship application written in Rust."
|
||||
</p>
|
||||
</Row>
|
||||
<Row>
|
||||
@@ -162,33 +163,36 @@ pub fn HomePage() -> impl IntoView {
|
||||
disabled=elements_disabled
|
||||
value=reactive_info.last_name
|
||||
/>
|
||||
</Row>
|
||||
<Row>
|
||||
<OutlinedTextField
|
||||
label="Contact Email"
|
||||
placeholder="temp@region15.org"
|
||||
label="Contact Email:"
|
||||
placeholder="student@region15.org"
|
||||
disabled=elements_disabled
|
||||
value=reactive_info.contact_email
|
||||
/>
|
||||
</Row>
|
||||
<Row>
|
||||
<Select
|
||||
value_list=vec!["Math", "English", "Science"]
|
||||
.into_iter()
|
||||
.map(|s| s.into())
|
||||
.collect()
|
||||
value=select_value
|
||||
<OutlinedTextField
|
||||
label="Phone Number:"
|
||||
placeholder="123-456-7890"
|
||||
disabled=elements_disabled
|
||||
value=reactive_info.phone_number
|
||||
/>
|
||||
</Row>
|
||||
<Row>
|
||||
<OutlinedTextField
|
||||
label="Street Address:"
|
||||
placeholder="123 Fake Street"
|
||||
disabled=elements_disabled
|
||||
value=reactive_info.address
|
||||
/>
|
||||
</Row>
|
||||
<Row>
|
||||
<RadioList
|
||||
selected=radio_value
|
||||
items=vec!["Test", "Testing 2"]
|
||||
.into_iter()
|
||||
.map(|s| s.into())
|
||||
.collect()
|
||||
disabled=elements_disabled
|
||||
/>
|
||||
<CheckboxList
|
||||
selected=chk_select
|
||||
items=vec!["Testing 1", "Testing 2"]
|
||||
label="Town:"
|
||||
selected=reactive_info.town
|
||||
items=vec!["Southbury", "Middlebury"]
|
||||
.into_iter()
|
||||
.map(|s| s.into())
|
||||
.collect()
|
||||
@@ -196,18 +200,35 @@ pub fn HomePage() -> impl IntoView {
|
||||
/>
|
||||
</Row>
|
||||
<Row>
|
||||
<ActionButton on:click=move |_| {
|
||||
console_log(
|
||||
format!("Found value {:?}", radio_value.get()).as_str(),
|
||||
);
|
||||
submit_action
|
||||
.dispatch(CreateSampleSubmission {
|
||||
student_info: reactive_info.capture(),
|
||||
});
|
||||
}>"Submit"</ActionButton>
|
||||
<Select
|
||||
label="Gender:"
|
||||
value_list=vec!["Male", "Female", "Prefer not to answer"]
|
||||
.into_iter()
|
||||
.map(|s| s.into())
|
||||
.collect()
|
||||
value=reactive_info.gender
|
||||
disabled=elements_disabled
|
||||
/>
|
||||
</Row>
|
||||
<Row>
|
||||
<ActionButton
|
||||
on:click=move |_| {
|
||||
submit_action
|
||||
.dispatch(CreateSampleSubmission {
|
||||
student_info: reactive_info.capture(),
|
||||
});
|
||||
}
|
||||
disabled=elements_disabled
|
||||
>"Submit"</ActionButton>
|
||||
</Row>
|
||||
<Row>
|
||||
<p>
|
||||
{result_msg}
|
||||
</p>
|
||||
</Row>
|
||||
</Panel>
|
||||
</div>
|
||||
<div class="flex flex-col flex-1"/>
|
||||
</Row>
|
||||
}
|
||||
})
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user