diff --git a/src/app.rs b/src/app.rs index 5673926..ba7f12c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,10 +1,7 @@ use leptos::prelude::*; use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title}; use leptos_oidc::{Auth, AuthParameters, AuthSignal, Challenge}; -use leptos_router::{ - components::{Route, Router, Routes}, - StaticSegment, -}; +use leptos_router::{components::{Route, Router, Routes}, path}; use url::Url; use crate::pages::{AboutPage, ComparisonTestPage, HomePage, ScholarshipInfoPage}; @@ -65,10 +62,10 @@ pub fn App() -> impl IntoView {
// TODO Create a 404 page - - - - + + + +
diff --git a/src/common/form_params.rs b/src/common/form_params.rs new file mode 100644 index 0000000..7a8368c --- /dev/null +++ b/src/common/form_params.rs @@ -0,0 +1,7 @@ +use leptos::Params; +use leptos_router::params::Params; + +#[derive(Params, PartialEq, Debug)] +pub struct ScholarshipFormParams { + pub id: Option, +} diff --git a/src/common/mod.rs b/src/common/mod.rs index bc24a28..3dd4824 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -3,5 +3,6 @@ mod expandable_info; mod form_schema; mod user; mod value_type; +mod form_params; -pub use self::{comparison::*, expandable_info::*, form_schema::*, user::*, value_type::*}; +pub use self::{comparison::*, expandable_info::*, form_schema::*, user::*, value_type::*, form_params::*}; diff --git a/src/pages/scholarship_info.rs b/src/pages/scholarship_info.rs index f598311..63bb3ab 100644 --- a/src/pages/scholarship_info.rs +++ b/src/pages/scholarship_info.rs @@ -1,7 +1,8 @@ use leptos::logging::log; use leptos::prelude::*; use leptos_oidc::{AuthLoaded, Authenticated}; -use crate::common::ExpandableInfo; +use leptos_router::hooks::use_params; +use crate::common::{ExpandableInfo, ScholarshipFormParams}; use crate::components::{ActionButton, ChipsList, Loading, OutlinedTextField, Panel, RadioList, Row}; use super::UnauthenticatedPage; use traits::{AsReactive, ReactiveCapture}; @@ -19,10 +20,18 @@ use super::api::{get_comparison_info, get_scholarship_info, CreateScholarshipInf /// changed before a full release. #[component] pub fn ScholarshipInfoPage() -> impl IntoView { - let scholarship_id = String::from("test-scholarship-id2"); + // let scholarship_id = String::from("test-scholarship-id2"); + let url_params = use_params::(); + let scholarship_id = move || { + url_params.read() + .as_ref() + .ok() + .and_then(|params| params.id.clone()) + .unwrap_or_default() + }; let get_scholarship_action: Resource = Resource::new( - move || scholarship_id.clone(), + move || scholarship_id().clone(), async |id| { get_scholarship_info(id.clone()).await // Note that this really should notify us of an error and then redirect or ask