feat: improve error handling and add documentation

This commit is contained in:
alphafetus committed 2025-12-19 12:48:22 -05:00
1 parent ddfac3dc2e
commit f74e5ca093
2 files changed
+46 -4

No files matched your search

+2 -2
View File
@@ -32,8 +32,8 @@ pub async fn get_scholarship_info(id: String) -> Result<ExpandableInfo, ServerFn
log!("Found output from API: {:?}", item);
Ok(serde_dynamo::from_item(item)?)
} else {
log!("Couldn't find any values, returning default struct.");
Ok(ExpandableInfo::new(id.clone()))
log!("Couldn't find scholarship with ID {:?}", id);
Err(ServerFnError::new("Couldn't find scholarship with given ID."))
}
}
Err(err) => {
+44 -2
View File
@@ -64,6 +64,25 @@ pub fn ScholarshipInfoPage() -> impl IntoView {
}
}
/// # Scholarship List Component
///
/// This component should always be wrapped in an Authenticated component. Assuming that a provider
/// is authenticated, this component will get all the scholarships that this provider owns and
/// will display them in a list, giving them the option to edit, delete, or create new scholarships.
///
/// It does not accept any props, and instead pulls the provider's information from the surrounding
/// environment.
///
/// Example usage:
/// ```
/// view! {
/// <AuthLoaded>
/// <Authenticated>
/// <ScholarshipList />
/// </Authenticated>
/// </AuthLoaded>
/// }
/// ```
#[component]
fn ScholarshipList() -> impl IntoView {
// Get scholarship provider information from authentication. This element will not display
@@ -158,12 +177,33 @@ fn ScholarshipList() -> impl IntoView {
}
}
/// # Scholarship List Entry Component
///
/// Displays a single scholarship within the [`ScholarshipList`] component.
///
/// Example usage (within the [`ScholarshipList`]):
/// ```
/// view! {
/// <ScholarshipListEntry
/// scholarship= /* An ExpandableInfo object containing scholarship info */
/// on_delete=move || log!("This is a callback on successful deletion.")
/// />
/// }
/// ```
#[component]
fn ScholarshipListEntry(
/// The scholarship information. This element will attempt to get the name of the scholarship
/// using its `name` field, and also utilizes the `subject` field.
#[prop()] scholarship: ExpandableInfo,
/// A [`Callback<()>`] that runs upon successful deletion of the scholarship.
#[prop(into)] on_delete: Callback<()>,
) -> impl IntoView {
let navigate = use_navigate();
let user_claims = get_user_claims();
let user_id = Memo::new(move |_| {
user_claims.get()
.map(|info| info.claims.subject.clone())
});
// Get the values that we need out of the info. We just need the subject and the name of
// the scholarship.
@@ -187,16 +227,18 @@ fn ScholarshipListEntry(
// Delete the scholarship.
let subject = subject.clone();
log!("Deleting scholarship with ID {:?}", subject);
if let Some(user_id) = user_id.get() {
spawn_local(async move {
match delete_provider_scholarship(
subject,
"".to_string()
user_id,
subject
).await {
Ok(_) => on_delete.run(()),
_ => {}
}
});
}
}
};
view! {