feat: improve getting server resources
This commit is contained in:
1 parent
b687125d9b
commit
bab47ac4af
1 file changed
+146
-137
+146
-137
@@ -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| {
|
||||||
get_scholarship_info(id).await
|
if let Some(id) = opt_id {
|
||||||
|
get_scholarship_info(id).await
|
||||||
|
} else {
|
||||||
|
Err(ServerFnError::new("Cannot get from server with no ID."))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -296,139 +300,144 @@ fn ScholarshipForm(
|
|||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Panel>
|
<Panel>
|
||||||
<Suspense fallback=Loading>
|
<Show
|
||||||
{move || {
|
when=move || scholarship_id.get().is_some()
|
||||||
scholarship_info.get()
|
fallback=|| view! { <p>"Choose a scholarship from the right, or create a new one."</p> }
|
||||||
.map(|res_scholarship| {
|
>
|
||||||
match res_scholarship {
|
<Suspense fallback=Loading>
|
||||||
Ok(scholarship) => {
|
{move || {
|
||||||
let reactive_info = scholarship.as_reactive();
|
scholarship_info.get()
|
||||||
|
.map(|res_scholarship| {
|
||||||
Either::Left(view! {
|
match res_scholarship {
|
||||||
<Row>
|
Ok(scholarship) => {
|
||||||
<h1 class="text-3xl font-bold">
|
let reactive_info = scholarship.as_reactive();
|
||||||
"Scholarship Info Form (test)"
|
|
||||||
</h1>
|
Either::Left(view! {
|
||||||
</Row>
|
<Row>
|
||||||
<Row>
|
<h1 class="text-3xl font-bold">
|
||||||
<OutlinedTextField
|
"Scholarship Info Form (test)"
|
||||||
label="Scholarship Name"
|
</h1>
|
||||||
placeholder="Example Scholarship Name"
|
</Row>
|
||||||
disabled=elements_disabled
|
<Row>
|
||||||
data_member="name"
|
<OutlinedTextField
|
||||||
data_map=reactive_info.data
|
label="Scholarship Name"
|
||||||
/>
|
placeholder="Example Scholarship Name"
|
||||||
</Row>
|
disabled=elements_disabled
|
||||||
<Row>
|
data_member="name"
|
||||||
<OutlinedTextField
|
data_map=reactive_info.data
|
||||||
label="Amount per award: (if multiple, enter the highest value)"
|
/>
|
||||||
placeholder="Enter an amount..."
|
</Row>
|
||||||
disabled=elements_disabled
|
<Row>
|
||||||
data_member="amount_per_award"
|
<OutlinedTextField
|
||||||
data_map=reactive_info.data
|
label="Amount per award: (if multiple, enter the highest value)"
|
||||||
input_type="number"
|
placeholder="Enter an amount..."
|
||||||
/>
|
disabled=elements_disabled
|
||||||
</Row>
|
data_member="amount_per_award"
|
||||||
<Row>
|
data_map=reactive_info.data
|
||||||
<OutlinedTextField
|
input_type="number"
|
||||||
label="Total number of awards:"
|
/>
|
||||||
placeholder="Enter an amount..."
|
</Row>
|
||||||
disabled=elements_disabled
|
<Row>
|
||||||
data_member="num_awards"
|
<OutlinedTextField
|
||||||
data_map=reactive_info.data
|
label="Total number of awards:"
|
||||||
input_type="number"
|
placeholder="Enter an amount..."
|
||||||
/>
|
disabled=elements_disabled
|
||||||
</Row>
|
data_member="num_awards"
|
||||||
<Row>
|
data_map=reactive_info.data
|
||||||
<OutlinedTextField
|
input_type="number"
|
||||||
label="Total amount of all awards:"
|
/>
|
||||||
placeholder="Enter an amount..."
|
</Row>
|
||||||
disabled=elements_disabled
|
<Row>
|
||||||
data_member="total_awards"
|
<OutlinedTextField
|
||||||
data_map=reactive_info.data
|
label="Total amount of all awards:"
|
||||||
input_type="number"
|
placeholder="Enter an amount..."
|
||||||
/>
|
disabled=elements_disabled
|
||||||
</Row>
|
data_member="total_awards"
|
||||||
<Row>
|
data_map=reactive_info.data
|
||||||
<RadioList
|
input_type="number"
|
||||||
data_member="fafsa_required"
|
/>
|
||||||
data_map=reactive_info.data
|
</Row>
|
||||||
items=vec!["Yes".to_string(), "No".to_string()]
|
<Row>
|
||||||
disabled=elements_disabled
|
<RadioList
|
||||||
label="Do you require student financial information?"
|
data_member="fafsa_required"
|
||||||
/>
|
data_map=reactive_info.data
|
||||||
</Row>
|
items=vec!["Yes".to_string(), "No".to_string()]
|
||||||
<Row>
|
disabled=elements_disabled
|
||||||
<RadioList
|
label="Do you require student financial information?"
|
||||||
data_member="transcript_required"
|
/>
|
||||||
data_map=reactive_info.data
|
</Row>
|
||||||
items=vec!["Yes".to_string(), "No".to_string()]
|
<Row>
|
||||||
disabled=elements_disabled
|
<RadioList
|
||||||
label="Do you require a student transcript?"
|
data_member="transcript_required"
|
||||||
/>
|
data_map=reactive_info.data
|
||||||
</Row>
|
items=vec!["Yes".to_string(), "No".to_string()]
|
||||||
<Row>
|
disabled=elements_disabled
|
||||||
<RadioList
|
label="Do you require a student transcript?"
|
||||||
data_member="award_to"
|
/>
|
||||||
data_map=reactive_info.data
|
</Row>
|
||||||
items=vec!["School".to_string(), "Student".to_string()]
|
<Row>
|
||||||
disabled=elements_disabled
|
<RadioList
|
||||||
label="Will the award be made to the school or the student?"
|
data_member="award_to"
|
||||||
/>
|
data_map=reactive_info.data
|
||||||
</Row>
|
items=vec!["School".to_string(), "Student".to_string()]
|
||||||
<Row>
|
disabled=elements_disabled
|
||||||
<RadioList
|
label="Will the award be made to the school or the student?"
|
||||||
data_member="essay_required"
|
/>
|
||||||
data_map=reactive_info.data
|
</Row>
|
||||||
items=vec!["Yes".to_string(), "No".to_string()]
|
<Row>
|
||||||
disabled=elements_disabled
|
<RadioList
|
||||||
label="Do you require a student essay?"
|
data_member="essay_required"
|
||||||
/>
|
data_map=reactive_info.data
|
||||||
</Row>
|
items=vec!["Yes".to_string(), "No".to_string()]
|
||||||
<Row>
|
disabled=elements_disabled
|
||||||
<RadioList
|
label="Do you require a student essay?"
|
||||||
data_member="essay_prompt"
|
/>
|
||||||
data_map=reactive_info.data
|
</Row>
|
||||||
items=vec!["Test 1", "Test 2", "Test 3"].iter().map(|s| s.to_string()).collect()
|
<Row>
|
||||||
disabled=elements_disabled
|
<RadioList
|
||||||
label="If so, select a prompt from the list below."
|
data_member="essay_prompt"
|
||||||
/>
|
data_map=reactive_info.data
|
||||||
</Row>
|
items=vec!["Test 1", "Test 2", "Test 3"].iter().map(|s| s.to_string()).collect()
|
||||||
<Row>
|
disabled=elements_disabled
|
||||||
<ChipsList
|
label="If so, select a prompt from the list below."
|
||||||
label="Scholarship Requirements"
|
/>
|
||||||
data_member="requirements"
|
</Row>
|
||||||
data_map=reactive_info.data
|
<Row>
|
||||||
values=comparison_ids
|
<ChipsList
|
||||||
displayed_text=comparison_text
|
label="Scholarship Requirements"
|
||||||
/>
|
data_member="requirements"
|
||||||
</Row>
|
data_map=reactive_info.data
|
||||||
<Row>
|
values=comparison_ids
|
||||||
<ActionButton
|
displayed_text=comparison_text
|
||||||
disabled=elements_disabled
|
/>
|
||||||
on:click=move |_| {
|
</Row>
|
||||||
let captured = reactive_info.capture();
|
<Row>
|
||||||
log!("Map values: {:?}", captured);
|
<ActionButton
|
||||||
submit_action.dispatch(CreateScholarshipInfo {
|
disabled=elements_disabled
|
||||||
info: captured
|
on:click=move |_| {
|
||||||
});
|
let captured = reactive_info.capture();
|
||||||
}
|
log!("Map values: {:?}", captured);
|
||||||
>"Submit"</ActionButton>
|
submit_action.dispatch(CreateScholarshipInfo {
|
||||||
</Row>
|
info: captured
|
||||||
<Row>
|
});
|
||||||
<p>{result_msg}</p>
|
}
|
||||||
</Row>
|
>"Submit"</ActionButton>
|
||||||
})
|
</Row>
|
||||||
|
<Row>
|
||||||
|
<p>{result_msg}</p>
|
||||||
|
</Row>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Either::Right(view! {
|
||||||
|
<p>"Error while getting scholarship: "{err.to_string()}</p>
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
}).collect_view()
|
||||||
Either::Right(view! {
|
}}
|
||||||
<p>"Error while getting scholarship: "{err.to_string()}</p>
|
</Suspense>
|
||||||
})
|
</Show>
|
||||||
}
|
|
||||||
}
|
|
||||||
}).collect_view()
|
|
||||||
}}
|
|
||||||
</Suspense>
|
|
||||||
</Panel>
|
</Panel>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user