All checks were successful
Push Workflows / rustfmt (push) Successful in 9s
Push Workflows / mdbook (push) Successful in 10s
Push Workflows / mdbook-server (push) Successful in 30s
Push Workflows / docs (push) Successful in 1m21s
Push Workflows / clippy (push) Successful in 1m18s
Push Workflows / leptos-test (push) Successful in 2m26s
Push Workflows / test (push) Successful in 2m37s
Push Workflows / build (push) Successful in 5m7s
Push Workflows / nix-build (push) Successful in 6m58s
Push Workflows / docker-build (push) Successful in 8m9s
27 lines
660 B
Rust
27 lines
660 B
Rust
use crate::prelude::*;
|
|
|
|
#[component]
|
|
pub fn LoadResource<T, S, C, V>(
|
|
resource: Resource<BackendResult<T>, S>,
|
|
children: C,
|
|
) -> impl IntoView
|
|
where
|
|
T: Send + Sync + Clone + 'static,
|
|
S: Send + 'static,
|
|
C: Fn(T) -> V + Send + 'static,
|
|
V: IntoView + 'static,
|
|
{
|
|
view! {
|
|
<Transition
|
|
fallback=move || view! { <Loading /> }
|
|
>
|
|
{move || resource.get().map(|resource|
|
|
match resource {
|
|
Ok(resource) => Either::Left(children(resource)),
|
|
Err(err) => Either::Right(err.to_component()),
|
|
}
|
|
)}
|
|
</Transition>
|
|
}
|
|
}
|