diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-30 09:15:56 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-30 09:15:56 +0200 |
| commit | d0263ce46160cd4152c67381fab2ee557f3aa483 (patch) | |
| tree | b24a725d71b984e466ff478fbb4449111beeacac /src/components/async_fetch.rs | |
| parent | chore: Second version (diff) | |
| download | web-client-d0263ce46160cd4152c67381fab2ee557f3aa483.zip | |
feat(treewide): Switch to tailwindcss and add more components
Diffstat (limited to 'src/components/async_fetch.rs')
| -rw-r--r-- | src/components/async_fetch.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/components/async_fetch.rs b/src/components/async_fetch.rs new file mode 100644 index 0000000..7105c6f --- /dev/null +++ b/src/components/async_fetch.rs @@ -0,0 +1,50 @@ +macro_rules! AsyncFetch { + (fetcher = $fetcher:block producer = |$bound_variable:pat_param| $producer:block) => {{ + use leptos::{ + prelude::{ElementChild, LocalResource, Suspend, Transition}, + view, + }; + + view! { + <Transition fallback=|| { + view! { <p>"Loading..."</p> } + }> + {move || Suspend::new(async move { + let resource = { LocalResource::new(move || $fetcher) }; + resource + .await + .map(|$bound_variable| $producer) + })} + </Transition> + } + }}; +} +pub(crate) use AsyncFetch; + +// #[component] +// pub fn AsyncFetch<P, V, T, Fut>( +// fetcher: impl Fn() -> Fut + 'static + Send + Sync, +// producer: P, +// ) -> impl IntoView +// where +// V: IntoView + 'static, +// P: Fn(T) -> V + 'static + Send + Sync, +// Fut: Future<Output = Result<T, Error>> + 'static, +// T: 'static, +// LocalResource<Result<T, Error>>: IntoFuture<Output = Result<T, Error>> + Send, +// { +// view! { +// <Transition fallback=|| { +// view! { <p>"Loading..."</p> } +// }> +// { || Suspend::new(async { +// let value_resource = LocalResource::new( || fetcher()); +// value_resource +// .await +// .map(|value| { +// producer(value) +// }) +// })} +// </Transition> +// } +// } |
