feat: improve getting server resources

This commit is contained in:
alphafetus committed 2025-12-19 12:20:05 -05:00
1 parent b687125d9b
commit bab47ac4af
1 file changed
+13 -4
+13 -4
View File
@@ -259,7 +259,7 @@ fn ScholarshipForm(
}); });
let comparison_list: Resource<Vec<ComparisonData>> = Resource::new( let comparison_list: Resource<Vec<ComparisonData>> = Resource::new(
move || (), // There's no input to this function. move || scholarship_id.get(), // There's no input to this function.
async move |_| { async move |_| {
get_comparison_info().await get_comparison_info().await
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
@@ -269,10 +269,14 @@ fn ScholarshipForm(
} }
); );
let scholarship_info: Resource<Result<ExpandableInfo, ServerFnError>> = Resource::new( let scholarship_info = Resource::new(
move || scholarship_id.get().unwrap_or_default(), move || scholarship_id.get(),
async move |id| { async move |opt_id| {
if let Some(id) = opt_id {
get_scholarship_info(id).await get_scholarship_info(id).await
} else {
Err(ServerFnError::new("Cannot get from server with no ID."))
}
} }
); );
@@ -296,6 +300,10 @@ fn ScholarshipForm(
view! { view! {
<Panel> <Panel>
<Show
when=move || scholarship_id.get().is_some()
fallback=|| view! { <p>"Choose a scholarship from the right, or create a new one."</p> }
>
<Suspense fallback=Loading> <Suspense fallback=Loading>
{move || { {move || {
scholarship_info.get() scholarship_info.get()
@@ -429,6 +437,7 @@ fn ScholarshipForm(
}).collect_view() }).collect_view()
}} }}
</Suspense> </Suspense>
</Show>
</Panel> </Panel>
} }
} }